News for hackers. Stuff that matters.
Re:JavaScript Interview Question by lhorie on Thursday January 20, 2011 @01:56PM (#2124791)
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

There are no comments on this comment yet.