Skip to main content

Command Palette

Search for a command to run...

What is CallStack in JavaScript?

Published
1 min read
S

I love learning about technology and sharing that with others

Motivation

I wanted to understand how the javascript actually runs in the browser.

CallStack

whenever a function is called it is pushed in to the stack and when it gets completed it will come out of the stack, this is similar concept that we have in java and many other languages that's how basically function calling works,

Example

function doSomethingA() {
    console.log("A");
}

function doSomethingB() {
    doSomethingA();
    console.log("B");
}

doSomethingB();
Understanding

first main will be called and pushed to the stack then doSomethingB() will be pushed to staack and it will start running in its first line we can see that it is calling another function doSomethingA() so doSomethingA will be pushed to the callstack and it will start executing there we are running console.log and then function will be finihsed means it will print A and removed from callstack now executnion comes to console.log(B) , it will print B and then function B will also come out of the stack.

More from this blog

H

hashcodehub

271 posts

Consistent, Passionate and Organized :)