The CodeLore

The CodeLore The CodeLore πŸ“œ

Explore the hidden mechanics behind programming. Because great developers understand the why behind the code. Concept Artist

Coding concepts, software architecture, and computer science ideas explained through stories, analogies, and visual thinking.

πŸ“œ The CodeLore  #1Understanding the JavaScript Event LoopMost developers write JavaScript code without fully understandi...
09/03/2026

πŸ“œ The CodeLore #1

Understanding the JavaScript Event Loop

Most developers write JavaScript code without fully understanding what happens behind the scenes. This illustration explains it visually using a simple airport analogy ✈️.

How it works:

1️⃣ Sync Queue (Fastest Lane) – Synchronous tasks like console.log() run immediately. They have 100% priority.

2️⃣ Microtask Queue (Priority Lane) – Tasks like Promises, process.nextTick(), fetch callbacks are VIP passengers. They always go before macrotasks.

3️⃣ Macrotask Queue (Regular Lane) – Tasks like setTimeout, setInterval, or I/O events wait their turn after microtasks.

Example Code:

console.log("A");
Promise.resolve().then(() => console.log("B"));
setTimeout(() => console.log("C"), 0);
console.log("D");

Ex*****on order:
A β†’ D β†’ B β†’ C βœ…

Why? All synchronous tasks run first, then microtasks, then macrotasks.
Airport Analogy ✈️

Picture an airport with three lanes:

VIP Fast Lane β†’ Sync tasks
Microtask Lane β†’ Promise callbacks, priority boarding
Regular Lane β†’ Macrotasks like setTimeout

The Event Loop is the airport manager checking which lane to serve next:
Always serve VIP first
Then microtasks
Finally, regular tasks
Repeat

πŸ’‘ Why it matters:
Understanding the Event Loop helps you write predictable, non-blocking code, avoid bugs, and think like a senior developer.
Follow The CodeLore to explore more coding concepts through storytelling, visuals, and analogies.

Address

Dhaka

Alerts

Be the first to know and let us send you an email when The CodeLore posts news and promotions. Your email address will not be used for any other purpose, and you can unsubscribe at any time.

Shortcuts

Share