Thursday, July 17, 2014 at 11: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: Sun, Nov 2, 2014 at 11:45 AM

By Dave Winer, Thursday, July 17, 2014 at 11:29 AM. Still diggin!