What does the memory phase do inside a JavaScript function?
It scans the body and allocates memory: parameters get their argument values, var declarations get undefined, let/const enter the TDZ, and inner function declarations are stored in full.
Verify This Answer
Cross-check this information using these trusted sources:
More FAQs in How Functions Work in JavaScript Under the Hood
A new function execution context is created, the memory phase allocates locals (var as undefined, functions in full), a frame is pushed on the call stack, the body runs line-by-line, and the frame is popped on return.
The part of an execution context that holds local variables, function arguments, and inner function declarations. Each function call has its own variable environment, so recursion and re-entrancy are safe.
Through the scope chain. Each execution context has an outer environment reference pointing to its lexical parent's environment. The engine walks this chain to resolve variables not found locally.
Still have questions?
Browse all our FAQs or reach out to our support team
