2 ms·
Valid, just doesn't do what you think. function foo() { var x = 1; if (true) { var x = 2; var y = 3; } console.log(x); console.log(y); } foo
by aboodman 16y ago
Valid, just doesn't do what you think.
function foo() {
var x = 1;
if (true) {
var x = 2;
var y = 3;
}
console.log(x);
console.log(y);
}
foo(); // 2, 3 (vs 1, undefined if there was block scope)
- drivebyacct2 16y agoThanks for the explanation!