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

RESOLVED DUPLICATE of bug 449811

Status

()

Core
JavaScript Engine
RESOLVED DUPLICATE of bug 449811
a year ago
a year ago

People

(Reporter: Josh Bass, Unassigned)

Tracking

Firefox Tracking Flags

(Not tracked)

Details

(Reporter)

Description

a year ago
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
Last Resolved: a year ago
Resolution: --- → DUPLICATE
Duplicate of bug: 449811
You need to log in before you can comment on or make changes to this bug.