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: Sun, Mar 22, 2015 at 5:51 PM

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