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

Jason Orendorff jason.orendorff at gmail.com
Tue Sep 30 03:38:55 PDT 2014


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
    }

-j


More information about the es-discuss mailing list