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?
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With