Member-only story

Call Stacks in Javascript

#2 of the 40 Essentials of Javascript — Call Stacks

Indy Seh
2 min readDec 23, 2022

The call stack is used by JavaScript to keep track of multiple function calls and this article describes what the call stack is and why it is needed in Javascript.

By the way, I have an Instagram Reel and Youtube Short on this Article, if you guys prefer that, please click here: Call Stack — Insta Reel, Call Stack — Youtube Short.

A call stack is a mechanism for an interpreter (like the JS interpreter in a web browser) to keep track of its place in a script that calls multiple functions — what function is being currently run and what other functions are called within that function.

It is like a real stack in data structure where data is pushed and popped and follows the Last In First Out (LIFO) principle.

LIFO — When we say that the call stack follows the data structure principle of Last In, First Out (LIFO), it means that the last function that gets pushed into the stack is the first to be pop out, when the function returns.

Lets understand call stack using a example.

function greetings() {
sayHello();
}

function sayHello() {
return "Hello!";
}

// Call the function greetings()
greetings();

Indy Seh
Indy Seh

Written by Indy Seh

Python | Go | Javascript | Typescript | Frontend | Backend

No responses yet

Write a response