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

Blocking the Event Loop

What happens when synchronous code takes too long and how it freezes the UI and delays all queued work.

Blocking the Event Loop

You'll learn what happens when synchronous code runs too long and how it freezes everything else waiting to execute.

The Core Problem

JavaScript is single-threaded, meaning it can only do one thing at a time. When a piece of synchronous code takes a long time to finish—like a massive loop or heavy calculation—it "blocks" the event loop. During this time, nothing else can happen: no queued tasks run, no microtasks execute, and in the browser, the UI completely freezes. The user can't click buttons, scroll, or type until that blocking code finishes.

Think of it like a single cashier at a checkout line. If one customer takes 10 minutes counting pennies, everyone behind them must wait. No other transactions happen until that customer is done.

What Gets Blocked

When the call stack is busy with slow synchronous code:

  • Task queue callbacks (like setTimeout) wait indefinitely
  • Microtasks (like Promise handlers) can't run
  • Browser rendering stops—the screen won't update
  • User interactions become unresponsive

The event loop can't move forward until the blocking code completes and the call stack is empty.

Why It Matters

Blocking the event loop creates a terrible user experience. A calculation that takes 3 seconds will make your webpage appear frozen. Users think it's broken. In Node.js, it prevents your server from handling other requests.

Key Takeaway: Long-running synchronous code blocks the entire event loop, freezing the UI and delaying all queued work. Keep synchronous operations short and move heavy work to async patterns or Web Workers.