Course contentsShow
← JavaScript
Lesson 1187 of 2,72327. The Event LoopFree lesson

Single-Threaded Execution

JavaScript has one call stack, meaning only one function executes at a time—no parallel function execution.

Single-Threaded Execution

You'll learn why JavaScript can only execute one function at a time, never running code simultaneously.

What Does "Single-Threaded" Mean?

JavaScript has one call stack, which means it can only do one thing at a time. Unlike some languages that can run multiple threads of execution in parallel, JavaScript executes functions one after another in a strict sequence. When a function is running, nothing else can run until that function completes.

Think of it like a single-lane road: only one car (function) can occupy that lane at any given moment. Other cars must wait in line behind it. There's no passing, no side-by-side driving—just one after another.

Why This Matters

This design choice means:

  • Predictable execution order: You always know the exact sequence of operations within synchronous code
  • No race conditions in your code: Two functions can never access the same variable at the exact same moment
  • Simplicity: You don't need complex locking mechanisms to protect shared data
  • Potential blocking: Long-running functions freeze everything else until they finish

When you call a function, it gets added to the call stack. JavaScript executes that function completely before moving to the next one. If that function calls other functions, they stack on top—but still, only the topmost function actually runs at any moment.

This single-threaded nature is why blocking operations are problematic: they halt the entire program. It's also why asynchronous patterns exist—to work around the limitations of having just one thread.

Key Takeaway: JavaScript's single call stack means only one function executes at any given moment—there is no parallel code execution, making the runtime predictable but potentially blocking.