Hoisting in JS
Main Concepts
Hoisting only with (variable or function) declaration
Function Declaration starts with `function`
if start not `function` ==> function expression.
examples (note none start with `function, self invoke is wrapped`):
#anonymous function expression var foo = function() { }
#named function expression var foo = function bar () { }
#self invoking function expression (function(){ })
function statement just pseudonym for function declaration
never place a Function Declarations in an if statement
place at top of scope to avoid confusion (explicit hoisting if you will)
Variable Declaration starts with `var`
initialization or expression after variable declaration is NOT hoisted
i.e. even with expression, all that is hoisted is var foo = undefined
Reference: https://javascriptweblog.wordpress.com/2010/07/06/function-declarations-vs-function-expressions/













