In ES6, do for loops with a let/const initializer create a separate scope?

Allen Wirfs-Brock allen at
Mon Jun 16 12:01:08 PDT 2014

On Jun 16, 2014, at 11:29 AM, Michael Zhou wrote:

> Thanks for the clarification, one detail about the order between incrementing and setting $$lastIteration_i:
> {
>    let i = $$lastIteration_i;   //create and initialize per iteration i
>    if (!(i<10)) break;
>   {
>       let i;
>    }
>    i++;
>    $$lastIteration_i = i;
> }
> Should it be
> $$lastIteration_i = i;
> i++;
> instead, given what the spec says?
neither of these desugarings is perfectly in alignment with the actual spec. which doesn't actually use a temp variable in this manner.

A closer match would be:

$$lastIteration_i = i;

The value of the new i for the next iteration is the incremented value of the previous i, but the value of the previous i is not incremented which is important for the cases where a closure has captured the previous i.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the es-discuss mailing list