Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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.



"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.


Spidermonkey (or whatever they are calling it nowadays) supports this using the "let" keyword, fwiw.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: