block scope + direct non-strict eval

Allen Wirfs-Brock allen at wirfs-brock.com
Tue Jan 31 12:57:20 PST 2012


On Jan 31, 2012, at 12:22 PM, Andy Wingo wrote:

> On Tue, 2012-01-31 at 10:13 -0800, Brendan Eich wrote:
>>>>>  (function (){let x = 20; eval("var x = 10"); return x;})()
>>>> 10
>>> 
>>> Surely a SyntaxError, as the var x conflicts with the let x at the
>>> function-level scope?
>> 
>> Oops, you're right. This is non-strict direct eval, so the var hoists 
>> and collides with the 'let'. Thanks!
> 
> Relatedly:
> 
>  (function (){ { let x = 20; eval ("var x = 10"); } return x;})()
> 
> SyntaxError because the "var x" gets hoisted past the "let x" ?

absolutely

Allen





More information about the es-discuss mailing list