Francisco Tolmasky (2015-01-23T01:03:19.000Z)
Apologies as I believe this has been discussed before (
https://esdiscuss.org/topic/block-scope-direct-non-strict-eval ), but just
trying to get some clarification as to the current state of things, and
have not been able to find this information (in a format I can understand).
Namely, I’m curious whether eval(“let x = 5”) adds x to the current scope,
if not in strict mode, at the “top level” (i.e. not in a function) and
called directly. My impression was that with let it should not be adding
anything to the current scope, but my tests in Mozilla Firefox (in the
console) seem to suggest they do:

> eval(“let x = 5”)
> undefined
> x
> 5

In fact, even in functions:

> (function() { eval("let xyz = 555"); console.log(xyz) })()
> 555

In if statements, it seems to be tacked onto the global scope:

> if (true) { eval(“let x = 5”) } x
> 5

If these are just bugs that’s fine, but if not, could someone tell me the
expected behavior? Is it always supposed to act as if its creating a new
scope for the blocks, or always *except* for top level evals? Or never?

Thanks,

Francisco

-- 
Francisco Tolmasky
www.tolmasky.com
tolmasky at gmail.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20150122/5ccad9e7/attachment.html>
tolmasky at gmail.com (2015-01-23T01:26:20.706Z)
Apologies as I believe this has been discussed before (
https://esdiscuss.org/topic/block-scope-direct-non-strict-eval ), but just
trying to get some clarification as to the current state of things, and
have not been able to find this information (in a format I can understand).
Namely, I’m curious whether eval(“let x = 5”) adds x to the current scope,
if not in strict mode, at the “top level” (i.e. not in a function) and
called directly. My impression was that with let it should not be adding
anything to the current scope, but my tests in Mozilla Firefox (in the
console) seem to suggest they do:

```javascript
> eval(“let x = 5”)
> undefined
> x
> 5
```

In fact, even in functions:

```javascript
> (function() { eval("let xyz = 555"); console.log(xyz) })()
> 555
```
In if statements, it seems to be tacked onto the global scope:

```javascript
> if (true) { eval(“let x = 5”) } x
> 5
```
If these are just bugs that’s fine, but if not, could someone tell me the
expected behavior? Is it always supposed to act as if its creating a new
scope for the blocks, or always *except* for top level evals? Or never?

Thanks,

Francisco
tolmasky at gmail.com (2015-01-23T01:25:57.014Z)
Apologies as I believe this has been discussed before (
https://esdiscuss.org/topic/block-scope-direct-non-strict-eval ), but just
trying to get some clarification as to the current state of things, and
have not been able to find this information (in a format I can understand).
Namely, I’m curious whether eval(“let x = 5”) adds x to the current scope,
if not in strict mode, at the “top level” (i.e. not in a function) and
called directly. My impression was that with let it should not be adding
anything to the current scope, but my tests in Mozilla Firefox (in the
console) seem to suggest they do:

```javascript
> eval(“let x = 5”)
> undefined
> x
> 5
```

In fact, even in functions:

> (function() { eval("let xyz = 555"); console.log(xyz) })()
> 555

In if statements, it seems to be tacked onto the global scope:

> if (true) { eval(“let x = 5”) } x
> 5

If these are just bugs that’s fine, but if not, could someone tell me the
expected behavior? Is it always supposed to act as if its creating a new
scope for the blocks, or always *except* for top level evals? Or never?

Thanks,

Francisco