Andy Farrell
1 min readOct 21, 2016

--

Honestly, this problem wouldn’t be nearly so bad if people were taught to write JavaScript properly, and not write it assuming it works the same as C or Java. Alas it’s too late for that I think; too many bad code examples abound already.

`for (var i… )` shouldn’t have been used in the first place, since as you show here it doesn’t work how it superficially appears to.

Of course, JS isn’t entirely blame-free here, since its syntax is clearly intended to resemble C/Java, so it’s natural that someone familiar with one of those languages would assume its variable scoping works the same.

--

--