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.
JavaScript Memory Allocation Phase Explained
What value do var variables get during memory allocation?
The answer
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.
Memory is allocated, but they remain uninitialized in the Temporal Dead Zone. Accessing them before the declaration line throws a ReferenceError.
Still have questions?
Browse all our FAQs or reach out to our support team
Want to upskill yourself?
Your learning library
Small steps. Big possibilities.
Find your next course. Build something great.