for-of with `const` variable

Isiah Meadows isiahmeadows at gmail.com
Sun Oct 18 10:28:35 UTC 2015


Thanks! (I forgot the Node REPL still runs in sloppy mode...)

On Sun, Oct 18, 2015 at 2:45 AM, Jordan Harband <ljharb at gmail.com> wrote:
> It's a v8 bug in sloppy mode, in that v8 sloppy mode is still using legacy
> let/const semantics.
>
> `'use strict'; for (const i of [1, 2, 3]) console.log(i)` will print out
> what you expect, since it properly rebinds per iteration.
>
> On Sat, Oct 17, 2015 at 11:09 PM, Isiah Meadows <isiahmeadows at gmail.com>
> wrote:
>>
>> I was toying around with for-of loops in Node 4.0, and I ran into the
>> following problem:
>>
>> ```
>> $ node
>> > for (let i of [1, 2, 3]) console.log(i)
>> 1
>> 2
>> 3
>> undefined
>> > for (const i of [1, 2, 3]) console.log(i)
>> 1
>> 1
>> 1
>> undefined
>> ```
>>
>> That second loop is rather surprising. Is that the correct behavior
>> (in which I need to file an ESLint bug), or is this a V8 bug?
>>
>> --
>> Isiah Meadows
>> _______________________________________________
>> es-discuss mailing list
>> es-discuss at mozilla.org
>> https://mail.mozilla.org/listinfo/es-discuss
>
>



-- 
Isiah Meadows


More information about the es-discuss mailing list