I was referring docs of JavaScript var hoisting
, There in a section i found Initialization of several variables with a Example given below.
var x = 0;
function f(){
var x = y = 1;
}
f();
console.log(x, y); // outputs 0, 1
// x is the global one as expected
// y leaked outside of the function, though!
Where I Suppose to get Exception as Uncaught Reference Error: y is not defined
.
but it is not happening due to leaked Scope and it is displaying 0,1
.
Can I Know why it is happening in detail and what made this to happen. Finally any performance related issues ?