BitlystBitlyst
PostsSeriesTopicsAbout

Bitlyst

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

© 2026 Mohsen Fallahnejad

PostsSeriesTopicsLinksAboutRSSGitHubX
Posts/javascript
Beginner2 min read

JavaScript is Single-Threaded

Understand what it means when people say JS is single-threaded.

Mohsen Fallahnejad

Mohsen Fallahnejad

Sep 23, 2025Discuss

🚦 What does "single-threaded" mean?#

  • A thread is like a worker that can do tasks.
  • JavaScript has only one worker (one thread).
  • That worker can do only one thing at a time.

So if JS is running some code, it cannot start another piece of code at the same exact time on another thread.


🛑 Why does this matter?#

  • If one task is slow (e.g. a heavy loop or waiting for a file), the single worker gets stuck.
  • This means your whole app (like a webpage) may freeze until the task finishes.

🍕 Analogy#

Imagine a pizza chef in a small restaurant:

  • There’s only one chef (single thread).
  • If the chef is busy making a pizza, he cannot simultaneously make pasta.
  • To handle waiting times (like pizza baking in the oven), the chef can set a timer and move to the next order.
  • That timer is like callbacks, promises, or async/await.

⚡ How does JS still feel fast?#

JavaScript uses the event loop + asynchronous operations:

  • Slow tasks (network calls, timers, etc.) are handed off to the browser / Node.js background helpers.
  • When they’re done, they say “Hey, I’m ready” and the single thread picks it up later.

This makes JS feel like it’s multitasking, even though only one thing runs at a time.


💻 Code Example#

js
console.log("Start");

setTimeout(() => {
  console.log("Async task done");
}, 0);

console.log("End");

Output#

code
Start
End
Async task done

👉 Even though the timeout is 0ms, the callback is delayed until the main thread finishes current tasks (Start and End).
This proves that JavaScript has only one main thread.


✅ Summary#

JavaScript is single-threaded = one main worker runs tasks one after another.
With the event loop + async, it can still handle multiple tasks smoothly without blocking.

Filed under#javascript#event loop#async

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 ↗
← OlderWhat is 'use client' in Next.js?Newer →JavaScript Promises Explained

Start the discussion

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

Read next

queueMicrotask Explained: The Smallest Async Queue in JavaScript

What queueMicrotask does, how it differs from Promise.then, and how microtasks really work under the hood.

Dec 31, 20251 min read1

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

Get new posts in your inbox

No spam. Unsubscribe any time.

2 min left
Discuss👍 React
👍