Why wouldn't `let` be exactly what you want? It's block scoped but doesn't need fancy TDZ checks because like `var` it just starts out as undefined.
Why wouldn't `let` be exactly what you want? It's block scoped but doesn't need fancy TDZ checks because like `var` it just starts out as undefined.
The article is slightly wrong. The TDZ is the zone before the variable is declared, not after. Referencing variables before they're declared isn't valid for `let` and hence it needs a TDZ check.
Consider
vs I think the article confuses "in scope" with "declared", and "declared and initialised" with "initialised".I think it’ll still throw a ReferenceError. Initialization is optional, but you still have to initialize before referencing.
Nope. `(() => {let bar; return bar})()` is `undefined`