Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SyntaxError: missing = in const declaration Firefox 50

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?

like image 455
wegry Avatar asked Aug 19 '16 17:08

wegry


1 Answers

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

like image 99
Felix Kling Avatar answered Nov 04 '22 07:11

Felix Kling