Execution Context


Execution context (EC) is defined as the environment in which the JavaScript code is executed. By environment, I mean the value of this, variables, objects, and functions JavaScript code has access to at a particular time.
Execution context is of three types as:
1️⃣ Global execution context (GEC):
This is the default execution context in which JS code start its execution when the file first loads in the browser. All of the global code which is not inside any function or object is executed inside the global execution context. GEC cannot be more than one.
2️⃣ Functional execution context (FEC):
Functional execution context is created whenever it finds any function call. Each function has its own execution context. It can be more than one. Functional execution context has access to all the code of the global execution context though vice versa is not applicable.
3️⃣ Eval:
Execution context inside eval function.
Example
var a = 10; // (1)
function functionA() {
	console.log("Start function A"); // (5)
	function functionB(){
		console.log("In function B"); // (4)
	}
	functionB(); // (3)
}

functionA(); // (2)
console.log("GlobalContext"); // (6)
💫 Call Stack (Execution stack)
  • 実行コンテキストを生成し、呼び出しスタック
  • にプッシュする.
  • LIFO