1. Topics
1.1. prototype
1.1.1. inheritance
1.1.1.1. uses prototype chains
1.2. equality
1.2.1. null
1.2.2. undefined
1.2.2.1. preferred
1.2.2.2. undefined is a type with exactly one value: undefined.
1.2.3. "" (empty string)
1.2.4. 0 (zero)
1.2.5. type coercion
1.2.6. === - strict equality operator
1.2.6.1. doesn't perform type coercion
1.2.6.1.1. better performance
1.2.7. objects compared by identity, on equality
1.3. types
1.3.1. Object.prototype.toString.call([]);
1.3.1.1. to get the [[Class]] property of the object
1.3.1.2. function is(type, obj) { var clas = Object.prototype.toString.call(obj).slice(8, -1); return obj !== undefined && obj !== null && clas === type; } is('String', 'test'); // true is('String', new String('test')); // true
1.3.2. typeof
1.3.2.1. is only useful for checking if the variable was defined
1.3.2.1.1. typeof xxx !== undefined
1.3.3. casting
1.3.3.1. string -> int
1.3.3.1.1. +'10'
1.3.3.2. string -> boolean
1.3.3.2.1. !!'value'
1.4. objects
1.4.1. everything is the object, except of null and undefined
1.4.2. numbers are also objects
1.4.2.1. (2).toString() 2 .toString() 2..toString()
1.4.3. accessing properties
1.4.3.1. dot notation
1.4.3.2. square brackets notation
1.4.3.2.1. for dynamic properties
1.4.3.2.2. for those who will raise error in dot notation
1.4.4. deleting properties
1.4.4.1. hasOwnProperty
1.4.5. notation of keys
1.4.5.1. either string or literal
1.5. scopes
1.5.1. Note: When not used in an assignment, return statement or as a function argument, the {...} notation will get interpreted as a block statement and not as an object literal. This, in conjunction with automatic insertion of semicolons, can lead to subtle errors
1.6. hoisting
1.6.1. // check whether SomeImportantThing has been initialized if (!SomeImportantThing) { var SomeImportantThing = {}; }
1.7. anonymous wrappers
1.7.1. encapsulate code
1.7.2. create namespace
1.8. arrays
1.8.1. use 'for' for iterate
1.8.2. length is not always cached
1.8.3. set length will truncate the array or create sparse array
1.9. tips
1.9.1. always use 'var'
1.9.2. use semicolon
1.9.2.1. automatic semicolon insertion by parser
1.9.2.1.1. return { }
1.9.2.1.2. log('testing!') (options.list || []).forEach(function(i) {})
1.9.2.2. keep braces on the same line with the statement
1.10. resources
1.10.1. MDN (Mozilla Developer Network)
1.10.2. Javascript Garden
1.10.3. ECMA Standard