Oriol Bugzilla (2016-04-15T17:52:10.000Z)
oriol-bugzilla at hotmail.com (2016-04-15T18:14:53.330Z)
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? Edit: I want to use `foo`, not workarounds like `window.foo`.
oriol-bugzilla at hotmail.com (2016-04-15T17:57:21.662Z)
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?