Name: Anonymous 2012-01-27 17:14
for (var i = 0; i < 5; i++) {}vs
var i;
for (i = 0; i < 5; i++) {}Not just Javascript, any language.
for (var i = 0; i < 5; i++) {}
var i;
for (i = 0; i < 5; i++) {}
{
int i;
for (i = 0; i < 5; i++) {}
}i's existence affects a lesser region of code. With the second one you at least know for sure there won't be any wasted instructions incrementing and decrementing the stack pointer while entering and exiting scope. I can't be sure what happens on the first (not just language, but compiler dependent) and too lazy to check, it could be equivalent emitted instructions after the compiler checks that i isn't used outside for.