Hoisting, scope and the dead zone
The scan that runs first
Before a line of a scope runs, every name in it already exists. · 10 minutes
Entering a scope is not nothing. Before the first statement runs, the machine walks the whole body and creates every binding it finds — `var` and function declarations holding `undefined` and their function, `let` and `const` created but unreadable.
That is why a function can be called above its own declaration, and why a `var` read early gives `undefined` rather than an error.
`console.log(x); let x = 1;` — what happens on the first line?