Is JavaScript single-threaded or multi-threaded?

JavaScript Async Basic Fresher1–2 Yrs Conceptual 1 min read

Quick Answer

JavaScript execution is single-threaded — one call stack, one thing at a time. Concurrency comes from the environment: the browser/Node handle I/O on other threads and queue callbacks for the single JS thread to pick up via the event loop. For real parallel CPU work you use Web Workers (browser) or worker_threads (Node), which run separate JS contexts.

The JavaScript engine runs your code on a single thread — one call stack. It doesn't do two things at once. What makes it feel concurrent is that the browser or Node runs the actual I/O — network, disk, timers — on other threads, and when that work finishes it puts a callback on a queue for the single JS thread to run when it's free. So async code isn't multi-threaded. If I need genuine parallelism for a heavy computation, that's a Web Worker, which is a separate thread with its own context that talks to the main thread by passing messages.

  • Async ≠ threads: setTimeout, fetch, file reads are handled by the host; your callback still runs on the one JS thread when the stack is clear.
  • A long synchronous loop freezes everything, including rendering — offload it to a worker.
  • Workers don't share memory (except via SharedArrayBuffer); they communicate by message passing.