15

I have a loop like the following:

const bar = {a: 1, b: 2}
for (const k in bar) { //Throws in Firefox but not Chrome 54
    console.log(k)
}

Is this a bug? Or maybe a gray area in the spec?

wegry
  • 7,046
  • 6
  • 39
  • 59

1 Answers1

15

Yes, this appears to be a bug in Firefox. The spec allows the use of const:

IterationStatement:
    for(ForDeclaration in Expression) Statement

ForDeclaration:
    LetOrConst ForBinding

ForBinding:
    BindingIdentifier
    BindingPattern

(truncated and simplified)

It seems Firefox is incorrectly interpreting ForDeclaration as a LexicalBinding.

Related: ECMAScript 2015: const in for loops

This seems like the bug report for this issue: https://bugzilla.mozilla.org/show_bug.cgi?id=1101653 .


Proper let and const is coming to Firefox: https://twitter.com/evilpies/status/768881995912994816

Community
  • 1
  • 1
Felix Kling
  • 795,719
  • 175
  • 1,089
  • 1,143
  • Huh, Firefox is making the same mistake I made when reading the spec. Didn't think to check for loops for special behavior. – ssube Aug 19 '16 at 18:27