Async callbacks run as separate invocations later, when the event loop pushes them onto an empty call stack. They are not nested inside the original caller's frame, which has already been popped.
How JavaScript Handles Nested Function Calls
How do async callbacks relate to nested function calls?
The answer
More FAQs in How JavaScript Handles Nested Function Calls
Each nested call pushes a new frame onto the call stack. The engine runs the top frame, returns its value, and pops it. The previous frame then resumes at the next statement.
Through the scope chain, which is based on where functions are written (lexical scope), not where they are called. The engine looks locally first, then follows outer environment references up the chain.
Each recursive call pushes a new frame with its own local variables. The stack grows with depth. When the base case returns, frames pop in reverse order and the return values combine on the way back up.
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.