In Javascript, variables declared with var
are implicitly “hoisted” to the beginning of a block.
Example
The following Javascript
{ console.log(a); var a = "value"; }
behaves as
{ var a; // Hoist. console.log(a); a = "value"; }
ES6 let
and const
does not have this behavior.