My JS notes Cheat Sheet

A Programming › JavaScript cheat sheet in English by dimitrios

My Javascript notes, stuff that I use often in the curent project I'm working on

12,060 views 3,675 downloads 21 Sep 2016 History
4.9 avg · 2 ratings

For loop

let iterable = [1, 2, 3];
for(let value of iterable) { consol­e.l­og(­value); }

Slice VS Splice

slice
shallow
splice
changes
The slice() method retrurns a shallow copy of a portion of an array into a new array object:
arr.slice([begin[, end]])

The splice method changes the content of an array by removing existing elements and/or adding new elements.
arr.sp­lic­e(s­tart, delete­Count [, item1 [, item2 ...]])

Chomp string

string = string.slice(0, -1);

Strings: substr VS substring

string.su­bst­r(s­tart, length)
string.su­bst­rin­g(s­tart, stop)

Clonin­g/A­ssi­gnment

Object.as­sig­n(obj1, obj2);
to clone:
let clone = Object.as­sig­n({}, obj1); // Though not sure if swallow or deep copy

"­Fal­sy" values in JS

Undefined
null
false
+0, -0, and NaN
"­"

Array aggreg­ation

array1 = array1.**concat**(array2);

Array includes element

array1.**includes**('xyz')

Case insens­itive compar­isson

(a, b) => a.toLowerCase().localeCompare(b.toLowerCase())

Logging companions

http:/­/1l­ine­art.ku­lao­ne.c­om/#/
http:/­/ba­da5­5.io/

For something like:
consol­e.l­og(­'%cd[ o_0 ]b %s', '­color: #fa573­2;', '­DAT­A');

Badges

Nice Cheat Sheet Good Cheat Sheet Downloaded from Unusual Locations × 2

Comments

No comments yet.

Cheatography n. The art of mapping complex subjects into clear, instantly navigable reference guides.