Facebook Pixel

Why are function declarations hoisted but not function expressions?

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.

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.

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.

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?

Our courses are taking a Coffee break, but your curiosity shouldn't. Stay engaged with namastedev linkedin, youtube, discord and other resources while you wait.

0
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.