BitlystBitlyst
PostsSeriesTopicsAbout

Bitlyst

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

© 2026 Mohsen Fallahnejad

PostsSeriesTopicsLinksAboutSync devicesRSSGitHubX
Posts/javascript
#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 read

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 read

Promise.all vs race vs any vs allSettled: When Do You Stop Waiting?

All four start your promises at once. The only difference is when each one stops waiting, and what counts as failure. Pick by that rule.

Dec 30, 20254 min read

Get new posts in your inbox

One email when a new post is out: short, diagram-first explanations of JavaScript, React and Next.js. No spam, unsubscribe any time.

1 min left
Discuss👍 React
👍