Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Temporal dead zone with let in for-loop

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?

like image 288
varkor Avatar asked Jan 02 '16 16:01

varkor


1 Answers

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.

like image 66
loganfsmyth Avatar answered Nov 12 '22 00:11

loganfsmyth