Declaration variables (i.e. var x; ) are valid for the entire area in which they are written, even if you declare after assignment. This means that "hoisting" : var x; rises to the beginning of the region, and the destination x = 6; excellent because x was declared somewhere in this area.
Strict mode does not change any of this. If you omit the var x; declaration var x; at all; without strict mode, the scope of the variable will be an implicitly global scope.
In ES2015 (aka ES6), lifting can be avoided by using the let keyword instead of var . (Another difference is that variables declared with let are local to the surrounding block, not to the whole function.)
source share