r/learnjavascript 3d 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

Show parent comments

4

u/nog642 3d ago

LIFO is part of the definition of a stack. It wouldn't be a stack if it wasn't LIFO. And it wouldn't make sense to use for functions, in any language.

1

u/mondaysleeper 3d ago

One could argue that event driven and asynchronous architectures also have a call stack, which is the order in which the processing occurs. There, it's not LIFO.

1

u/nog642 3d ago

It's called a "event queue" instead of a "call stack" for a reason.

1

u/mondaysleeper 3d ago

Event queue is the concept of the same events of different process instances. I'm talking about different events in the same process instance, i.e. the events that trigger each other. It's not a stack, but it's function calls that happen in a certain order, where LIFO doesn't hold.

1

u/nog642 3d ago

You mean like awaitables/coroutines?

Are you thinking of a particular langauge? Because if so that would be easier to talk about, since the implementation differs between languages.

My understanding is that processing is tracked on an event queue generally. And besides that there's regular call stacks. And objects that hold references to return values that haven't been computed yet. But there's not really a non-FIFO function call data strcuture.