When is a setTimeout callback's execution context created?
When the event loop pushes the callback onto the call stack, not when setTimeout is called. The original function may have returned long before.
Verify This Answer
Cross-check this information using these trusted sources:
More FAQs in JavaScript Function Invocation and the Call Stack
An execution context is created, memory is allocated for locals, a frame is pushed onto the call stack, the body runs line-by-line, and the frame is popped on return. The return value is passed to the caller.
It immediately pops the current function's frame from the call stack. The return value is handed to the calling function, which resumes at the next statement.
At invocation (except for arrow functions). The way you call the function (plain, method, call, apply, bind, new) determines this. Arrow functions inherit this from their lexical scope at definition time.
Still have questions?
Browse all our FAQs or reach out to our support team
