Take let variable out of temporal dead zone

Oriol Bugzilla oriol-bugzilla at hotmail.com
Fri Apr 15 17:52:10 UTC 2016


Consider this code:
```html
<script>
let {foo} = null; // TypeError
</script>
<script>
// Here I want to assign some some value to foo
</script>
```

The first script attempts to let-declare `foo` via a destructuring assignment. However, `null` can't be destructured, so the assignment throws a TypeError.
Some alternatives which would lead to the same problem are `let foo = null.throw` and `let foo = (() => {throw;})()`.

Then the `foo` variable is declared but uninitialized, so if in the 2nd script I attempt to reference `foo`, it throws:
```js
foo = 123; // ReferenceError: can't access lexical declaration `foo' before initialization
```

And `let` variables can't be redeclared:
```js
let foo = 123; // SyntaxError: redeclaration of let foo
```

Is this behaviour intended? Is there any way to take `foo` out of the TDZ, so that I can assign values and read them?

- Oriol
 		 	   		  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20160415/88512236/attachment.html>


More information about the es-discuss mailing list