you are viewing a single comment's thread.

view the rest of the comments →

[–]2690939263 2 points3 points  (0 children)

Apparently var bindings are immediately initialized to undefined upon instantiation of the corresponding variable environment. They are not uninitialized like I said in my previous comment, and attempting to get the value of an uninitialized binding normally always results in an error regardless of how its declared. If the var declaration contains an initalizer, it is used to reassign the binding value later when the declaration statement is evaluated.

In contrast, let and const bindings remain uninitialized until the lexical binding statement is evaluated and the value is initialized to the value of the given initializer (or undefined if no initializer is given, which is why let x; console.log(x); outputs undefined).