A code block (if,for, etc.) defines a scope only for variables declared with theletandconstkeywords. Thevarkeyword is limited to function scope, meaning that new scope can only be created inside functions. Theletandconstkeywords have block scope, which creates a new, local scope for any bl...
Meaning: The block of code is aware of the variable, but it cannot be used until it has been declared. Using aletvariable before it is declared will result in aReferenceError. The variable is in a "temporal dead zone" from the start of the block until it is declared: ...
In this example, the local variable isfunction-scoped. Variables declared with thevarkeyword are always function-scoped, meaning they recognize functions as having a separate scope. This locally-scoped variable is therefore not accessible from the global scope. The new keywordsletandconst, however, ...