The JavaScript Call Stack

What is it?

The JavaScript engine uses a call stack to keep track of the scripts and functions that are executing.

When a script is executed, the JavaScript enginge creates a global execution context and pushes it to the stack.

When a function is called, the JavaScript engine creates a function execution context for that function and pushes it to the stack.
If a function calls another function, the JavaScript engine creates a new function execution context for the function being called and pushes it to the stack.

Visualizing the JavaScript Function Call Stack

See how the call stack responds when you try to calculate the average of two numbers.

Enter two numbers:

Call Stack