Thursday, July 17, 2014 at 10:29 AM

Gobal JavaScript for loop index

I just learned that this:

for (i = 0; i < subs.length; i++)

Is very different from:

for (var i = 0; i < subs.length; i++)

Especially if it's in a recursive routine.

In the first case, i is a global. In the second it's local.

You might argue that the first case is useless and the language should only allow locals in that spot.

But this is JavaScript.

There should be a special smiley that you put after that last sentence.


Last built: Wed, Jan 28, 2015 at 5:21 AM

By Dave Winer, Thursday, July 17, 2014 at 10:29 AM. Yeah well, that's just, you know, like, your opinion, man.