Call Stack - JamesDansie/data-structures-and-algorithms GitHub Wiki

Call Stack

Author: James Dansie

The call stack and the event loop are the things that make our code execute. First we'll start with the call stack. The call stack is a LIFO(Last In First Out). This means that the last thing that was put on the stuck will be the first thing popped off the stack. Think of it is a stack of sticky notes to do. The last one put on the stack is going to be the first one you grab off it. This is the synchronous part the code, everything goes in the exact order from top to bottom.

The event loop is what allows us to be asynchronous. Instead of everything waiting its turn to execute, the event loop will give a promise, while it runs off and fulfills the promise. This video is fantastic for explaining this; https://www.youtube.com/watch?v=8aGhZQkoFbQ&t=1424s seriously, go watch it.

(from here; https://medium.com/front-end-weekly/javascript-event-loop-explained-4cd26af121d4)


Sources;