The answer
When the function returns. Its frame is popped from the call stack and its local variables become eligible for garbage collection unless captured by a closure.
When the function returns. Its frame is popped from the call stack and its local variables become eligible for garbage collection unless captured by a closure.
The global context is created once at program start and lives until the program ends. A function context is created every time a function is called and is destroyed when it returns.
Exactly one per program. It sits at the bottom of the call stack for the entire lifetime of the script.
In a browser, this points to the window object. In Node.js modules, this points to module.exports (or globalThis in modern code).
Browse all our FAQs or reach out to our support team
Your learning library
Find your next course. Build something great.