ajmalafif
2/28/2015 - 6:47 AM

[js] — learning

[js] — learning

Type & Type Coercion

Fire up console and question these:

5 - "4"  // 1
5 + "4"  // 54
+!{}[true]  
+[1]  
+[1,2]  
7 - "a"  
7 / 0  

Operators

5 + "4"
5 + null
4 == "4.00"
null == undefined
0 == false
0 == null
null == false

typeof null == "object" // should be null
typeof function() {} == "function" // should be object

Objects & Primitives

Not all things in JS in an object. Know the difference.

var a = "string";
alert(a.length); // 6
a.t = 3
alert(a.t); // undefined

Functions & Constructors

has 3 phases.

  1. Use as function
  2. Use as object
  3. Use as constructor, to create new object

Closures

function add(a) {
 return function (b) {
return a + b;
};

add(3)(4) == 7

Prototypes