BitlystBitlyst
PostsSeriesTopicsAbout

Bitlyst

Short, diagram-first posts on JavaScript, React & Next.js. Follow via RSS or the newsletter.

© 2026 Mohsen Fallahnejad

PostsSeriesTopicsLinksAboutRSSGitHubX
Posts/javascript
Beginner1 min read

JavaScript's Event Loop — Simple Guide (with SVG Timeline)

Event loop explained with a clean SVG timeline showing the actual execution order: Start → End → Promise → Timeout.

Mohsen Fallahnejad

Mohsen Fallahnejad

Sep 20, 2025Discuss

The event loop lets JavaScript handle async tasks on a single thread.

Example Code#

js
console.log("Start");

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

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

console.log("End");

Output: Start → End → Promise → Timeout


Visual Timeline (SVG)#

Event Loop SVGEvent Loop SVG


Why this order?#

  • Start and End are synchronous → run immediately on the call stack.
  • Promise.then is a microtask → runs before macrotasks.
  • setTimeout callback is a macrotask → runs after microtasks drain.
Filed under#javascript#event-loop#async#promises#frontend#diagram

Was this worth your time?

One tap tells me what to write more of.

Mohsen Fallahnejad

Written by

Mohsen Fallahnejad

Frontend engineer explaining JavaScript, React & Next.js internals in posts you can finish over coffee. More about me

X ↗GitHub ↗LinkedIn ↗
← OlderMicrotask vs Macrotask in JavaScript — With Node.js vs Browser NotesNewer →React Higher-Order Components (HOC)

Start the discussion

Questions, corrections, a better approach? I read and reply to every comment.

Read next

Why async/await Doesn’t Make JavaScript Code Parallel

Async/await feels like parallel code, but it isn’t. Here’s why JavaScript is still single-threaded and how async really works.

Dec 30, 20253 min read1

How Promise.all Works in a Single-Threaded JavaScript World

If JavaScript is single-threaded, how can Promise.all handle multiple requests at the same time? A deep dive into the event loop and async I/O.

Dec 30, 20252 min read1

Promise APIs Compared: all vs race vs any vs allSettled

A practical and conceptual comparison of Promise.all, Promise.race, Promise.any, and Promise.allSettled.

Dec 30, 20253 min read2

Get new posts in your inbox

No spam. Unsubscribe any time.

1 min left
Discuss👍 React
👍