Toplevel 'let' binding can be left permanently uninitialized after an error

Rick Waldron waldron.rick at gmail.com
Tue Sep 30 10:00:34 PDT 2014


On Tue, Sep 30, 2014 at 6:38 AM, Jason Orendorff <jason.orendorff at gmail.com>
wrote:

> On Mon, Sep 29, 2014 at 4:14 PM, Rick Waldron <waldron.rick at gmail.com>
> wrote:
> > Can you clarify "write"? Does this mean assignment?
>
> Yes.
>
> > Why would assignment throw?
>
> Assigning to an uninitialized variable is an error in ES6. A
> let-binding is initialized when its declaration is evaluated. So this
> is OK:
>
>     let x;  // no Initializer, so it's initialized to undefined
>     console.log(x);  // logs undefined
>
> but this is not:
>
>     init();
>     let answer;
>     function init() {
>         answer = 42;  // throws ReferenceError
>     }
>

My original response questions were poorly asked. I understand the TDZ
semantics, but I couldn't reproduce anything meaningful from your original
example, because I don't have the SpiderMonkey build that includes the let
updates (presumably Nightly doesn't either, because none of these can be
reproduced there). I'm trying to understand when/where/why/how the original
example could happen and what the potential consequences are in terms of
practical application.


Rick
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20140930/df25041a/attachment-0001.html>


More information about the es-discuss mailing list