Advanced & AsyncTuesday, January 27, 2026

The Event Loop

How JS handles concurrency.

Advertisement

Support JS Mastery Path by checking out our sponsors.

JavaScript is single-threaded. It has one Call Stack. The Event Loop is the traffic controller that decides what goes onto that stack.

The Priority Lane (Microtasks)

Not all tasks are equal.
MacroTasks (setTimeout, setInterval): Regular lane.
MicroTasks (Promises, QueueMicrotask): VIP Lane.

The Event Loop always empties the VIP lane (Promises) before processing the next regular car (setTimeout).

The Ultimate Quiz

Predict the order before running this. This is a very common interview question.

console.log("1. Start");

setTimeout(() => {
  console.log("2. Timeout (Macro)");
}, 0);

Promise.resolve().then(() => {
  console.log("3. Promise (Micro)");
});

console.log("4. End");

/*
Order Logic:
1. "Start" (Synchronous)
2. "End" (Synchronous)
3. "Promise" (Microtask Queue - Higher Priority)
4. "Timeout" (Macrotask Queue - Lower Priority)
*/
Advertisement

Support JS Mastery Path by checking out our sponsors.