What is the JavaScript execution context?
Answer
An execution context is the environment in which JavaScript code is evaluated and executed. There are three types: Global Execution Context (GEC) — created on page load; the default context; creates the global object (window in browser, global in Node) and sets this to it. Function Execution Context (FEC) — created whenever a function is called. Eval Execution Context — rarely used. Each execution context has: a Variable Environment (all var declarations and function declarations, hoisted), a Lexical Environment (current scope + outer scope reference), and a binding for this. Contexts are managed by the call stack — when a function is called, its context is pushed; when it returns, it is popped. The outer environment reference forms the scope chain. Understanding execution contexts explains hoisting (variables/functions are processed before code runs within each context), closures (inner contexts reference outer environments), and this binding.
Previous
What is prototype pollution in JavaScript?
Next
What is memory management and garbage collection in JavaScript?