Jeffrey Way writing for Net Tuts:
Variable Declarations are Hoisted
Within its current scope, regardless of where a variable is declared, it will be, behind the scenes, hoisted to the top. However, only the
declaration
will be hoisted. If the variable is alsoinitialized
, the current value, at the top of the scope, will initially be set toundefined
.
A good tip for the flux of new developers coming over to the JavaScript world. Hoisting is definitely a gotcha I remember running into. Read the whole thing for examples, it’s a good explanation.