Hoisting and Execution Context
What is the JavaScript execution context?
The JavaScript execution context is the environment in which JavaScript code is evaluated and executed. It's a conceptual container that tracks the execution of code, manages variables, and defines the value of `this`. Every time JavaScript code runs, it runs inside an execution context. There are three types of execution contexts: 1. Global Execution Context: Created when a JavaScript script starts running - it's the default context where code that isn't inside any function is executed. 2. Function Execution Context: Created whenever a function is called - each function call creates its own execution context. 3. Eval Execution Context: Created when code is executed inside an `eval()` function. Each execution context has two phases: the Creation Phase and the Execution Phase. During the Creation Phase, the JavaScript engine sets up the Variable Environment, creates the scope chain, and determines the value of `this`. During the Execution Phase, the code is executed line by line. Understanding execution contexts is fundamental to understanding JavaScript's behavior regarding variables, scope, and the `this` keyword.