JS... - JS includes keyval as language construct (aka associative array/hashtable/dictionary), this brings confusion and multiple ways to do 1 thing (as objects, arrays, and functions can be interchangeable) - everything is an object, if that wasn't enough, JS is reflective, at any point we may add/mutate properties of object e.g. foo.newmember = "bar"; Best practices / rule of thumb - when in doubt how to store data, always start with JSON (don't sore functions) - always use 'var' keyword unless you're dereferencing a global Functions - all functions are objects - 'this' keyword can be used in function if it is being new'ed (as in creating object/instance), if function was called without 'new' then this.foo will bind to window.foo ... - NEW keyword, JS expects a constructor when new'ing, this implies we should NEW a function, new'ing e.g. 'new {} throws TypeError: object is not a function' [references] http://msdn.microsoft.com/en-us/library/ie/d1et7k7c%28v=vs.94%29.aspx [data types] - built-ins? the keval/dictionary/hash/associate-array language construct - primitive string, number boolean - composite (reference) object, array rvalues: new Object(), Object(), function() {}, {} rvalues: [], new Array(), Array() - special null, undefined note: null is not 0, does not have type, undefined is a string [scope] - var keyword is used to make local variables [anonymous functions] wrapping code inside of 'function() { code } ()' is handy for creating a namespace for your code and restricting scope, since js essentially has a global and function scope, we don't want to pollute and cause collisons [closures] in JavaScript, if you use the function keyword inside another function, you are creating a closure. if a function containing function f returns that function, that variable points to f and also to the closure, unlike C, where stack frame would get destroyed, so f has access to variables/object in the context it was defined in - what about function returning a function that's a good way to leverage closures! ['this' and 'prototype' object and the 'new'] - every object has a prototype object - the keyword 'this' refers to the object context within which the the function is executing - protype is used for templating, it provides access to members of an object, when function is assigned to this object, only 1 copy exists, it is memory efficient, also we get expected behavior when overriding that function - 'new' changes meaning of a function, upon invocation, function is ran in blank object context [some examples] > 4 - 2 is 2 > 4 - "2" is 2 > "4" + 2 is "42" > 0 == false true > 1 == "1" true (js > 1 === "1" false (no type coercion is taking place) > [] + [] "" empty string > [] + {} {object Object] Object > {} + [] 0 > {} + {} NaN ~~~~~----- BROWSER -----~~~~~ [JS in a browser] - there are 3 main global objects 1) window......is the execution context and global object for that context's JS 2) document....contains the HTML 3) screen......describes the physical display's full screen - your code gets executed inside something that looks like with (window) { //Your code } - console.log is not available in to use from within HTML->JS, however it does exist in browser's console (Ctrl+Shift+k or F12) ~~~~~----------~~~~~