We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
Javascript
Cheat Sheet
JSBle ETot Le ico)
var num = [1, 2, 3, 4];
[Link](1) (eRe)
[Link](5) // Add element to the end: [1, 2, 3, 4, 5]
Due) LO} // remove last element: [1, 2, 3]
Clee oa) // €i11 every element: [1, 1, 1, 1]
Pease) // remove first element: [2, 3, 4]
[Link](5) // Add element to beginning: [5, 1, 2, 3, 4 ]
num. reverse() // sort in descending order: [4, 3, 2, 1]
num. ineludes(2) // is array contains a specified value; true
[Link]( item => 2*item) // Map elementsz; [2, 4, 6, 8]
[Link]( item => item > 2) // filter elemet: [3, 4]
[Link](item => item > 2) // Find element ; 3(first match)
[Link](item => item > 0) ena 3
[Link](item => item === 2) // 1
[Link]( (prev, curr) => prev + curr, 9) // 10
Chester O Na aS Se
[Link](" * "); FE Soins 7h he seas a4
[Link](2, @, "i", "p"); // add elements ; [1, 2, 'i', ‘p', 3, 4]
[Link](1,4); // slice elements from [1] to [4-1]
[Link](); // sort string alphabetically
[Link](function(a, b){return a - b}); // numeric sort
[Link](function(a, b){return b - a}); // numeric descending sort
[Link](function(a, b){return 6.5 - [Link]()}); // random sortJavascript Dates
var d = new Date();
Date("2017-86-23") ; TA me Chee CoE Theol
Date("2617"); // is set to Jan @1
Date("2617-66-23T12:00:00-09:45"); // YYYY-MM-DDTHH:MM:SSZ
Date("June 23 2017"); ee OL Ch mh
Date("Jun 23 2017 07:45:00 GMT+0530"); // time zone
a = [Link](); // getting the weekday
[tata Oi // day as a number (1-31)
getDay(); TLC AMM tee)
getFullYear(); Time) am baer a ae hO b a)
getHours(); // hour (@-23)
getMilliseconds(); // milliseconds (0-999)
getMinutes(); metas eeD)
getMonth(); 7/ month (6-11)
getSeconds(); // seconds (8-59)
aaa Oi TAM ey ole Mee ot)Errors Handlings
try { Ae Solel a) alle
undefinedFunction() ;
catch(err) { // block to handle errors
console. log([Link]) ;
y
Ame oan Pei etl)
var x = [Link]("mynum").value;
cto aan 8
if(x == "") throw "empty"; // error cases
if(isNaN(x)) throw "not a number";
x = Number(x);
if(x > 10) throw "too high";
catch(err) { // if there's an error
[Link]("Input is " + err); A alee
[Link](err); // write the error in console
Vi
beurre nang
Tameka a Tee Ro a eh ol
[Link]("Done");
)Javascript JSON
var str = '{"names":[' + // crate JSON object
'{"first" :"Hakun: lastN":"Matata" },' +
'{"first":"Jane","lastN":"Doe" },' +
Ga gall of pet toey GUA oils Fy -§ aM Fay ef Leg [Par
myObj = [Link](str); Perey
document .write([Link][1].first) ; access
var myJSON = [Link](my0bj); Sater aa
[Link]("testJSON", myJSON) ; Eisele til Meet hee)
text = [Link]("testJSON") ; toa kl (e Meh}
Javascript Object
var student = { object name
Bee) ea BEE amo alee) eet ele ME RALLY
Bsa) F-1 od-
age:18,
height:17@,
SPO UCU MPMn a Toast) Ort // object function
“ "+ [Link];
0
Me
Sale ante hod Sasi mn Pal
student[age]++; incrementing
name = student. fullName(); call object function
lee ene a eCMouse
Keyboard
Frame
Form
Drag
Animation
Bee E Tilo] a aval cs)
onclick, oncontextmenu, ondblclick,
onmousedown, onmouseenter, onmouseleave,
CTT hme ULC Lam LU EL LoL ae
CTU Ett) )
yn cos l LL