4 ms·
They're "hoisted" and only local to the function, though. I'd (personally) prefer it if it worked like C, and a variable was defined from the "var" statement un
by udp 16y ago
They're "hoisted" and only local to the function, though. I'd (personally) prefer it if it worked like C, and a variable was defined from the "var" statement until the next closing brace. Then you could have a variable local to one branch of an if statement, etc, without faking scopes by abusing closures (eg (function() { })(); ).
And nested loops that both use "i" would work.
- deleted 16y ago[deleted]
- sedachv 16y ago"I'd (personally) prefer it if it worked like C, and a variable was defined from the "var" statement until the next closing brace." It does work like C. The scoping you're talking about was introduced in C99.
- cyrus_ 16y agoSpidermonkey (or whatever they are calling it nowadays) supports this using the "let" keyword, fwiw.