No, the code should not output 2, because variable declarations go up, so your code is equivalent
var x = 1; (function() { var x; x = 2;
Line
x = 2;
only changes the internal variable x , which obscures the external object.
The volume of a non-global variable is an integer function in which it is declared. From the beginning of this function to its end.
source share