
What is the Event Loop?
How JavaScript is executed in browsers
In one single sentence, moving events from the task queue to the call stack is called the “event loop”. But in order to fully understand how the event loop works, you also need to understand three other things in JavaScript:
- The stack: The order in which your code is being executed, is handled by the call stack. You can think of it as an array that holds a list of command on what to execute next.
- The web API thread: Everything that is not part of the JavaScript engine, is handled by a separate thread. Think of the various functions you get in the browser, such
setTimeout
or aPromise
. - The task queue: Everything that is waiting to be executed is stored in the task queue. Such as a callback funcion from a
setTimeout
. Until the task queue is empty again, the event loop will process the next message in the queue and puts it into the stack.

Resources:
📚 More Webtips
Master the Art of Frontend
Access exclusive interactive lessons
Unlimited access to hundreds of tutorials
Remove ads to learn without distractions