A fun little spec deviation in the major JS engines

Andreas Rossberg rossberg at google.com
Mon Jan 30 01:47:27 PST 2012


On 29 January 2012 04:13, Jeff Walden <jwalden+es at mit.edu> wrote:
> At least, if you consider |with| and |eval| fun (and who doesn't?):
>
>  js> var x = "outer"; function f() { with({ x: 17 }) eval("var x"); return
> x; } typeof f()
>  "undefined"

This is really just an instance of JavaScript's, er, creative rules
for var-hoisting. You need neither `eval' nor `with' to witness them,
the same happens with

var x = "outer"; function f() { with({ x: 17 }) { var x } return x; } typeof f()

or

var x = "outer"; function f() { try { throw 17 } catch(x) { var x }
return x; } typeof f()

That's why you will want to use `let' in the future. :)

/Andreas


More information about the es-discuss mailing list