Web Programming - Week 3 Flashcards
What are HTML Events
Activities performed by user to control the page which can execute JavaScript code
Syntax of defining an event attribute
< element eventname = code >
Common HTML events
onchange onclick onmouseover onmouseout onkeydown onload
How to define an object
var ObjectName = new Object(); OR var ObjectName = {..} comma instead of semi colon
What is the purpose of “this” in a function
Refers to the owner of the function
JavaScript prebuilt objects
Array - Makes a list with [] or () Date - (YY/MM/DD) Maths String Number JSON
Common String Methods
length
indexOf(string)
toUpperCase()
trim()
Common Number Methods
toString()
toFixed(number)
Number()
parseInt()
parseFloat()
isNan()
Common Array Methods
toString()
join(separator)
pop() - Removes and returns last value
push() - Adds new value
shift() - Removes first value
unshift() - Adds new element at beginning
reverse()
Syntax of calling sort
arr.sort([compareFunction])
compareFunction defines alternative sort order
Compare Function Structure
array.sort(function(a,b){
return a - b;
});
Arrow Compare Function Structure
array.sort((a,b) => a - b);
Common Math Methods
PI round() min() max() random()
Creating a Date object
new Date(); - Today's date new Date(year, month, day, hours...) new Date(dateString);
Common Date Methods
getFullYear()
getMonth()
toString()