3 ms·
No, it doesn't because j is in the same scope as i. Your confusion is because of a javascript quirk for (...) { var foo = bar } is actually the same
by lhorie 16y ago
No, it doesn't because j is in the same scope as i.
Your confusion is because of a javascript quirk
for (...) {
var foo = bar
}
is actually the same as
var foo
for (...) {
foo = bar
}
Notice how you only ever have one foo
What you need is:
for (...) {
(function(bar) {
var foo = bar
})(bar)
}
which create a new foo every time you loop