Show Menu
Cheatography

JS Tips Cheat Sheet (DRAFT) by

sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss

This is a draft cheat sheet. It is a work in progress and is not finished yet.

Comments

//
recomm­ended
/ /
those pairs can occur in regular expression literals, so block comments are not safe for commenting out blocks of code

Simple types

numbers
strings
booleans
null
undefined
All other values are objects. Numbers, strings, and booleans are object­-like in that they have methods, but they are immutable

Objects in JavaScript are mutable keyed collec­tions

In JavaSc­ript, arrays are objects, functions are objects, regular expres­sions are objects, and, of course, objects are objects.

Objects

An object is a container of proper­ties, where a property has a name and a value
property name
any string, including the empty string
property value
any JS value, except for undefiend
Objects in JS are class-free
Objects can contain other objects, so they can easily represent tree or graph structures
JavaScript includes a prototype linkage feature that allows one object to inherit the properties of another - this can reduce object initia­liz­ation time and
memory consum­ption.
 

String

** - escape character
Js does not have a charater type - make a string just with one character in it
length property - "­sev­en".l­ength = 5
immutable - Once it is made, a strng can never be changed. But it is easy to make a new string by concat­enating other strings together with the + operator
'c' + 'a' + 't' === 'cat' - two strings containg exactly the same characters in the same order are considered to be the same string
JavaScript was built at
a time when Unicode was a 16-bit character set, so all characters in JavaScript are 16
bits wide.

Object Literals

An object literal is a pair of curly braces surrou­nding zero or more name/value pairs.
Commas are used to separate the pairs
var empty_­obejct = {}
var stooge = { "­fri­st-­nam­e" : "­Teo­", last_name = "­G"}
 

Numbers

integer
fraction
exponent
100 and 1e2 are the same. (multi­plying the e by 10 raised to the power of the part after e)
NaN
number value.NaN is not equal to any value, including itself. Detect NaN with isNaN(­number) function
Ininity
All values greater than 1.7976..e+308
Numbers have methods
Math object that contains a set of methods thata ct on numbers
JavaScript has a single number type. Intern­ally, it is repres­ented as 64-bit floating
point, the same as Java’s double. Unlike most other progra­mming languages, there is
no separate integer type, so 1 and 1.0 are the same value