Closed Bug 1321848 Opened 3 years ago Closed 3 years ago

Using let keyword with (for..in) and (for..of)

Categories

(Core :: JavaScript Engine, defect)

defect
Not set

Tracking

()

RESOLVED DUPLICATE of bug 449811

People

(Reporter: jbass86, Unassigned)

Details

Was writing an webapp in the latest version of firefox (50.0.2) and noticed while using let in a for loop declaration that it doesn't behave as I would expect. 

The following code for example:

  var something = {a: "a", b: "b", c: "c"};

  for (let name in something){

    window.setTimeout(()=>{
      console.log(name);
    }, 1000);
  }

will yield the following output :

Chrome(54.0.2840.99):
  a
  b
  c

Firefox(50.0.2):
  c
  c
  c

The same behavior seems to be present with (for..of) as well.  It does seem however that if you use "for (let i = 0; i < x; i++)" syntax then the variable will be scoped correctly.  

I tested this on Redhat Rhel7, Windows7 and Windows10.
This should be fixed in Firefox 51, which also happens to be the current Firefox beta release.
Status: UNCONFIRMED → RESOLVED
Closed: 3 years ago
Resolution: --- → DUPLICATE
Duplicate of bug: 449811
You need to log in before you can comment on or make changes to this bug.