The Call Stack and Execution Contexts
As we saw in the previous article, the call stack executes our code with execution contexts.
What's an Execution Context?
Variable Environment:
Scope Chain:
"this" keyword:
Let's take a look at an example:
const age = 30;
const add10 = () => {
let a = 10 + sum(8, 15);
return a;
}
function sum(x, y) {
return x + y;
}
const result = add10();
console.log(`Result of 8 + 15 + 10: ${result}`);
console.log(`The age is ${age}`);
Global Execution Context:
age = 30
add10 = <function>
sum = <function>
result = unknown
add10 Execution Context:
a = unknown
sum Execution Context:
arguments = [8, 15]
The call stack looks as follows: