JavaScript quick reference
Statements
break terminates the current while or for loop
continue continues execution of the loop with the next iteration
for ([initial-expression;] [condition;] [increment-expression]) {
statements
} creates a loop
for (variable in object) {
statements
} creates a loop
if (condition) {
statements
} [else {
statements
}] executes a set of statements if a specified condition is true or false
switch(variable) {
case value_1:
statements;
break;
...
default:
statements;
} can be used for multiple statements branches
while (condition) {
statements
} creates a loop that executes a statements if condition is true
do {
statements
} while (condition) creates a loop that executes a statements if condition is true
Math Functions
isNaN(value) is value not a number
parseFloat(string) returns a floating-point number
parseInt(string [,base]) returns an integer of the specified base
abs(value) absolute value of a number
sin(value), cos(value), tan(value), asin(value), acos(value), atan(value) trigonometric functions
max(x,y), min(x,y) highest/lowest value of x and y
String and Array Functions
length number of characters in a string or elements in array
charAt(index) character at a specified position
charCodeAt(index) character code at a specified position
concat(string1,string2...,stringN)
concat(array1,array2...,arrayN) Joins two or more strings or arrays and returns the result
eval(string) evaluates a string of JavaScript code
join(separator) joins elements of an array into a string and separate each element with separator
indexOf(searchvalue,fromindex) position of the first occurrence of a specified string value
lastIndexOf(searchvalue,fromindex) position of the last occurrence of a specified string value
replace(findstring,newstring) replaces findstring characters with newstring characters in a string
slice(start,end) extracts a part of a string or array and returns the extracted part
split(separator, array_size) splits a string by separator into an array of strings
substr(start,length)
substring(start,stop) returns the characters in a string between two specified indices
toLowerCase()
toUpperCase() returns a string in lowercase/uppercase letters
pop() removes and returns the last element of an array
push() adds element(s) to the end of an array
reverse() reverses elements position of an array
sort(sortby) sorts elements of an array
Date Functions
Date() today's date and time
getDate(), getMonth(), getFullYear(), getHours(), getMinutes(), getSeconds(), getMilliseconds()returns the selected value from a Date object
getDay() returns day of the month from a Date object
setMonth(month[,day]), setFullYear(year[,month,day]), setHours(hour[,min,sec,millisec]), setMinutes(min[,sec,millisec]) sets a date or time in a Date object
Events
onabort, onerror loading is interrupted / an error occurs when loading
onblur, onfocus element loses or gets focus
onchange field changed
onclick, ondblclick mouse clicks/doubleclicks on an object
onkeydown, onkeyup, onkeypress keyboard key pressed / released / pressed or held
onreset, onsubmit reset/submit form button is clicked
onload, onunload page is loaded/user close the page
onmousedown, onmousemove, onmouseout, onmouseover, onmouseup mouse movement events
onresize window is resized
No comments:
Post a Comment