Is hoisting caused by moving code to the top?
No. Hoisting is a side effect of memory allocation. The engine does not rearrange code; it allocates memory for declarations before executing the code phase.
Verify This Answer
Cross-check this information using these trusted sources:
More FAQs in JavaScript Memory Allocation Phase Explained
The first phase of execution context creation. The engine scans the code, allocates memory for variables and functions, assigns undefined to var variables, places let/const in the TDZ, and stores function declarations in full.
Function declarations are fully stored during memory allocation. Function expressions are treated as variables assigned undefined (with var), so calling them before assignment throws a TypeError.
undefined. The declaration is hoisted but the assignment is not. Only when the code execution phase reaches the assignment line does the variable get its real value.
Still have questions?
Browse all our FAQs or reach out to our support team
