Single Threaded

JavaScript is famously single-threaded. No matter how powerful your processor is, a standard JavaScript program can only utilize a single core at a time. It can only execute one single instruction at a time, meaning no two computations in your JavaScript code will ever run simultaneously.

How can it perform well?

You might think that being single-threaded makes JavaScript terrible at handling heavy workloads. However, JavaScript is actually incredibly powerful when it comes to asynchronous programming because it is non-blocking.

The simplest way to think about it is this: JavaScript can only execute one instruction at a time, but it can continue processing other code while it is waiting for something external to complete.

CPU Bound vs I/O Bound

If the tasks your application performs are I/O bound (Input/Output), JavaScript performs exceptionally well. It can easily handle thousands of concurrent operations because it simply pushes them to the background while waiting.

  • Network requests
  • File system operations
  • Timers
  • Database queries

However, if your tasks are heavily CPU bound (requiring intense math, cryptography, or image processing), JavaScript will struggle. Because it only has one thread, a heavy calculation will physically block the thread, preventing any other code from running until the calculation finishes.