classes to the top of their scope. Before execution of the code.
Types of hoisting
We can categorieze hoisting into three following behaviors.
1) Value hoisting
Use a variable's value in its scope before the line it is declared. For
2) Declaration hoisting
Reference a variable in its scope before the line it is declared, without throwing a ReferenceError, but the value is always undefined. For
All variables get hoisted.
- When the
varvariables are hoisted they are initialized with the value
- When the
constvariables are hoisted they are not initialized with any value. (That is the reason the temporal dead zone exists.)
3) Class hoisting
A class declaration is uninitialized when hoisted. (TDZ like
Temporal Dead Zone (TDZ)
The declaration of the variable causes behavior changes in its scope before the line in which it is declared. For
TDZ with line shadowing:
TDZ for automatically global variables:
TDZ for classes:
There is not a specific justification or definition for hoisting variables and functions. Infact there is no such thing as hoisting.
The JS code interpretation performed in two passes.
Code compilation step, the interpreter processes variable and function declarations. It puts all variable and function declarations in memory as it figures out the lexical scopes that exists in the program.
Code execution step, the interpreter processes function expressions and undeclared variables.
"It puts all variable and function declarations in memory" Is the part where