with + let

Bradley Meck bradley.meck at gmail.com
Fri Feb 5 18:25:22 UTC 2016


`var` is hoisted and unified for multiple definitions (each definition
refers to 1 hoisted variable slot). `let` cannot have multiple definitions
that are in the same lexical scope. Using `var` inside the loop would have
no effect since it is unified to the declaration outside of the loop.

On Fri, Feb 5, 2016 at 12:21 PM, Francisco Tolmasky <tolmasky at gmail.com>
wrote:

> Just curious how the following code should behave:
>
> ```javascript
> var a = { x: 10 };
> with (a)
> {
>    let x = 20;
> }
>
> console.log(a.x);
> ```
>
> a.x is still 10 in a repl I tried. However, if it was var x in the with x
> would be 20. Is let not affecting the with expected behavior?
>
> --
> Francisco Tolmasky
> www.tolmasky.com
> tolmasky at gmail.com
>
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20160205/3c1afbb8/attachment.html>


More information about the es-discuss mailing list