This is not just a PDF page becase it's interactive! Find code for JS loops, variables, objects, data types, strings, events and many other categories. JavaScript Cheat Seet contains useful code examples on a single page. Online Interactive JavaScript (JS) Cheat Sheet length i ++) ) // random order sortĬoncat, copyWithin, every, fill, filter, find, findIndex, forEach, indexOf, isArray, join, lastIndexOf, map, pop, push, reduce, reduceRight, reverse, shift, slice, some, sort, splice, toString, unshift, valueOf Var dogs = new Array( "Bulldog", "Beagle", "Labrador") // declaration alert(dogs) // access value at index, first item being ĭogs = "Bull Terier" // change the first item for (var i = 0 i < dogs. getDate() + 7) // adds a week to a date setDate() // day as a number (1-31) setFullYear() // year (optionally month and day) setHours() // hour (0-23) setMilliseconds() // milliseconds (0-999) setMinutes() // minutes (0-59) setMonth() // month (0-11) setSeconds() // seconds (0-59) setTime() // milliseconds since 1970) getDay() // getting the weekday getDate() // day as a number (1-31) getDay() // weekday as a number (0-6) getFullYear() // four digit year (yyyy) getHours() // hour (0-23) getMilliseconds() // milliseconds (0-999) getMinutes() // minutes (0-59) getMonth() // month (0-11) getSeconds() // seconds (0-59) getTime() // milliseconds since 1970 Setting part of a date var d = new Date() ĭ. random() // random number between 0 and 1 Math. max( 0, 3, - 2, 2) // = 3 - the highest value Math. abs( - 3.14) // = 3.14 - absolute, positive value Math. pow( 2, 8) // = 256 - 2 to the power of 8 Math. MIN_VALUE // smallest possible JS number Number. MAX_VALUE // largest possible JS number Number. valueOf() // returns number Number( true) // converts to number Number( new Date()) // number of milliseconds since 1970 parseInt( "3 months") // returns the first number: 3 parseFloat( "3.5 days") // returns 3.5 Number. Pi.toFixed( 2) // returns 3.14 - for working with money Transitionend, onmessage, onmousewheel, ononline, onoffline, onpopstate, onshow, onstorage, ontoggle, onwheel, ontouchcancel, ontouchend, ontouchmove, ontouchstart Onabort, oncanplay, oncanplaythrough, ondurationchange, onended, onerror, onloadeddata, onloadedmetadata, onloadstart, onpause, onplay, onplaying, onprogress, onratechange, onseeked, onseeking, onstalled, onsuspend, ontimeupdate, onvolumechange, onwaitingĪnimationend, animationiteration, animationstart Ondrag, ondragend, ondragenter, ondragleave, ondragover, ondragstart, ondrop Onblur, onchange, onfocus, onfocusin, onfocusout, oninput, oninvalid, onreset, onsearch, onselect, onsubmit Onabort, onbeforeunload, onerror, onhashchange, onload, onpageshow, onpagehide, onresize, onscroll, onunload Mouse onclick, oncontextmenu, ondblclick, onmousedown, onmouseenter, onmouseleave, onmousemove, onmouseover, onmouseout, onmouseup Person // member !(a = b) // logical notĪ ! = b // not equal typeof a // type (number, object, function.)Ī + = b // a = a + b (works with - * %.) 100 / 48 remainder = 4Ī ++ b - // postfix increment and decrement Bitwise operators & X = 1 // Throws an error because variable is not declared Values false, true // boolean 18, 3.14, 0b10011, 0xF6, NaN // number "flower", 'John' // string undefined, null, Infinity // special Operators a = b + c - d // addition, substractionĪ = b * (c / d) // multiplication, division Let z = 'zzz' // block scope local variable Strict mode "use strict" // Use strict mode to write secure code
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |