We can use let
statements in for
loops, with multiple variable assignments, for example:
for (let x = 0, y = 0; x < 10; ++ x);
However, we start getting discrepancies in implementations if we reference one variable from another; the following results in working code in Chrome, but a ReferenceError in Firefox:
for (let x = 0, y = x; x < 10; ++ x);
Firefox seems not to assign x
to y
under after the entire expression has been parsed, whereas Chrome does it immediately. Note that the following works in both browsers (the same statement outside of a for
block):
let x = 0, y = x; // x = 0, y = 0
It seems as if Firefox's implementation is incorrect (especially after considering the case outside the for
block), but what does the ES6 specification say about this? Is this something that needs to be (or has already) been reported?
Firefox's let
is an old non-standard implementation. The best place to look is http://kangax.github.io/compat-table/es6/. Assuming you are on Firefox Stable (43), not that it is currently listed has having zero support for ES6 let
.
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