4 ms·
That's not how function-level scoping works in Javascript. function p() { if(false) var p = 10; return p; } p(); // evaluates to undefi
by reissbaker 14y ago
That's not how function-level scoping works in Javascript.
function p() {
if(false) var p = 10;
return p;
}
p(); // evaluates to undefined
What you'd get in a block-scoped language is some sort of ReferenceError; you still don't get 10 in JS, though. The variable is accessible outside of the block, but the block itself isn't executed. The above is just equivalent to the following transformation:
function p() {
var p;
if(false) p = 10;
return p;
}
p();
Aesthetic offense is a matter of taste. I prefer Scheme over C for aesthetic beauty, but many prefer the opposite.