In Javascript, there are only two kinds of scope; scope and global scope.
The code inside the operator ifdoes not have its own scope, so the variable inside the operator ifis the same as the external one.
. var if , , .
, , , , :
var foo = 1;
(function() {
console.log(foo)
foo = 2;
if(false) {
var foo = 3;
}
console.log(foo)
})();
console.log(foo)