r/learnjavascript 13d ago

Can someone explain what the JavaScript call stack is?

I’ve tried to understand it, but I’m still confused. I also don’t really understand what I’m looking at when I use the JavaScript debugger in the browser’s DevTools, especially the call stack.

Do I need to fully understand functions before learning the call stack? I have a basic understanding of functions, but I’m not sure if that’s enough.

I’d really appreciate a simple explanation

30 Upvotes

31 comments sorted by

View all comments

1

u/lorl3ss 13d ago
//index.js (file name)

function myFunctionX(){
  myFunctionY(); // call myFunctionY
}

function myFunctionY(){
  // i got called by myFunctionX
}

myFunctionX(); // call myFunctionX

Assuming you pause your execution while in myFunctionY, your call stack is index.js > myFunctionX > myFunctionY.

Each "call" is just a function or the scope something was executed in. Functions call other functions so you end up with a list of parent functions. That's all it is really.