0% found this document useful (0 votes)
9 views3 pages

JavaScript JS Cheat Sheet Online

This document is a JavaScript cheat sheet that covers essential topics such as strings, events, arrays, and promises. It provides various methods and properties for manipulating strings and arrays, handling events, and working with promises. The cheat sheet serves as a quick reference for JavaScript syntax and functionalities.

Uploaded by

xaqim3
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views3 pages

JavaScript JS Cheat Sheet Online

This document is a JavaScript cheat sheet that covers essential topics such as strings, events, arrays, and promises. It provides various methods and properties for manipulating strings and arrays, handling events, and working with promises. The cheat sheet serves as a quick reference for JavaScript syntax and functionalities.

Uploaded by

xaqim3
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

JavaScript (JS) Cheat Sheet Online

[Link]/js/

Strings⊗
Selectors specify which elements are targeted with a style

var abc = "abcdefghijklmnopqrstuvwxyz";


var esc = 'I don\'t \n know'; // \n new line
var len = [Link]; // string length
[Link]("lmno"); // find substring, -1 if doesn't contain
[Link]("lmno"); // last occurance
[Link](3, 6); // cuts out "def", negative values count from behind
[Link]("abc","123"); // find and replace, takes regular expressions
[Link](); // convert to upper case
[Link](); // convert to lower case
[Link](" ", str2); // abc + " " + str2
[Link](2); // character at index: "c"
abc[2]; // unsafe, abc[2] = "C" doesn't work
[Link](2); // character code at index: "c" -> 99
[Link](","); // splitting a string on commas gives an array
[Link](""); // splitting on characters
[Link](16); // number to hex(16), octal (8) or binary (2)

Events 🕖
1/3
Event handlers in JavaScript.

<button onclick="myFunction();">
Click here
</button>

Mouse

onclick, oncontextmenu, ondblclick, onmousedown, onmouseenter, onmouseleave,


onmousemove, onmouseover, onmouseout, onmouseup

Keyboard

onkeydown, onkeypress, onkeyup

Frame

onabort, onbeforeunload, onerror, onhashchange, onload, onpageshow, onpagehide,


onresize, onscroll, onunload

Form

onblur, onchange, onfocus, onfocusin, onfocusout, oninput, oninvalid, onreset, onsearch,


onselect, onsubmit

Drag

ondrag, ondragend, ondragenter, ondragleave, ondragover, ondragstart, ondrop

Clipboard

oncopy, oncut, onpaste

Media

onabort, oncanplay, oncanplaythrough, ondurationchange, onended, onerror, onloadeddata,


onloadedmetadata, onloadstart, onpause, onplay, onplaying, onprogress, onratechange,
onseeked, onseeking, onstalled, onsuspend, ontimeupdate, onvolumechange, onwaiting

Animation

animationend, animationiteration, animationstart

Miscellaneous

transitionend, onmessage, onmousewheel, ononline, onoffline, onpopstate, onshow,


onstorage, ontoggle, onwheel, ontouchcancel, ontouchend, ontouchmove, ontouchstart

Arrays≡

2/3
[Link](); // convert to string: results
"Bulldog,Beagle,Labrador"
[Link](" * "); // join: "Bulldog * Beagle * Labrador"
[Link](); // remove last element
[Link]("Chihuahua"); // add new element to the end
dogs[[Link]] = "Chihuahua"; // the same as push
[Link](); // remove first element
[Link]("Chihuahua"); // add new element to the beginning
delete dogs[0]; // change element to undefined (not
recommended)
[Link](2, 0, "Pug", "Boxer"); // add elements (where, how many to remove,
element list)
var animals = [Link](cats,birds); // join two arrays (dogs followed by cats and
birds)
[Link](1,4); // elements from [1] to [4-1]
[Link](); // sort string alphabetically
[Link](); // sort string in descending order
[Link](function(a, b){return a - b}); // numeric sort
[Link](function(a, b){return b - a}); // numeric descending sort
highest = x[0]; // first item in sorted array is the lowest
(or highest) value
[Link](function(a, b){return 0.5 - [Link]()}); // random order sort

concat, 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

PromisesÞ
An object, used for asynchronous computations. A Promise represents a value which may be
available now, or in the future, or never.

States

pending, fulfilled, rejected

Properties

[Link], [Link]

Methods

[Link](iterable), [Link](iterable), [Link](reason), [Link](value)

3/3

You might also like