Js Cheat-Sheet
Js Cheat-Sheet
com
var a = 10; if (a === b) { Return absolute value Math.abs(x) Join strings string.concat()
// code;
var b = 20; } Return arccosine Math.acos(x) Checks if a string ends with x string.endsWith()
Strings var month = 'January'; Return lowest value Math.min(x,y,z) Rtn matches against a RegEx string.match()
switch(month) {
var a = “string”; case 'January': Return highest value Math.max(x,y,z) Replace string at position x string.replace()
function myFunction() { default: Return square root Math.sqrt(x) Extract x number of characters string.substr()
// code here; //code
} } Return tangent Math.tan(x) Extract between 2 positions string.substring()
function myFunction(num1,num2) { var i = 1; Add to beginning of array array.unshift(x) Convert string to upper case string.toUpperCase()
alert(num1 * num2);
} while(i < 10) { Add to end of array array.push(x) Remove whitespace from beg/end string.trim()
document.write(i + "<br>"); Remove from beginning of array array.shift() Return primitive value of string obj string.valueOf()
i++
Objects } Remove from end of array array.pop(x) Number methods
var phone = new Object(); Do While loop Reverse array order array.reverse() Return string in exponential notation number.toExponential()
phone.manufacturer = “Apple”;
phone.model = “iPhone”; var i = 1; Remove element between 2 positions array.slice(x,x) Return number in fixed-point notation number.toFixed()
1
Popular Properties Dates & Date methods Operators DOM & Events
Math properties New date object new Date(); Assignment Shorthand Triggered when clicked onclick
(Same as)
Return Euler, approx 2.718 Math.E Get methods Assignment x=y (x = y) Triggered when change detected onchange
Return natural logarithm of 2. approx 0.693 Math.LN2 Get day of month getDate() Addition x += y (x = x + Triggered when user enters page onload
y)
Return natural logarithm of 10, approx 2.303 Math.LN10 Get day of week getDay() Subtraction x -= y (x = x - y) Triggered when user leaves page onunload
Base 2 logarithm of E, approx 1.443 Math.LOG2E Get year (yyyy) getFullYear() Multiplication x *= y (x = x * Triggered when mouse moves over a element onmouseover
y)
Base 10 logarithm of E, approx 0.434 Math.LOG10E Get hour of day getHours() Division x /= y (x = x / Triggered when a mouse moves out of a element onmouseout
y)
Return the value of PI, approx 3.141 Math.PI Get milliseconds 0-999 getMilliseconds() Remainder(Mod x %= y (x = x / Triggered when mouse button pressed down onmousedown
ulus) y)
Returns square root of 1/2, approx 0.707 Math.SQRT1_2 Get minutes 0-59 getMinutes() Arithmetic Operator Triggered when mouse button released onmouseup
Returns square root of 2, approx 1.414 Math.SQRT2 Get month getMonth() Addition + Triggered when keyboard button pressed down onkeydown
String properties Get seconds 0-59 getSeconds() Subtraction - Triggered when keyboard button released onkeyup
Returns the string’s constructor function string.constructor Get the time since 1/1/70 getTime() Multiplication * Triggered when keyboard button is pressed onkeypress
Return string’s length string.length Set methods Division / Triggered when error occurs with loading a onerror
external file
Used to add properties to a string object string.prototype Set day of month setDate() Remainder(Mod % Triggered after user makes selection onselect
ulus)
Number properties Set year (yyyy) setFullYear() Increment ++ Triggered when a form is submitted onsubmit
Return largest possible number in JS Number.MAX_VALUE Set hour of day setHours() Decrement -- Triggered when an element is dragged ondrag
Return smallest possible number in JS Number.MIN_VALUE Set milliseconds 0-999 setMilliseconds() Comparison Operator Triggered when an element is dropped ondrop
Not a number value Number.NaN Set minutes 0-59 setMinutes() Equality == Triggered when a screen is touched ontouchstart
Represents negative infinity Number.NEGATIVE_INFINITY Set month setMonth() Strict equality === Triggered when a finger is removed from screen ontouchend
Logical Operator
And &&
Or ||
Not !