An event loop is a mechanism that lets a program handle many tasks on a single thread by taking them one at a time from a queue and running each to completion before grabbing the next. It is the reason a language like JavaScript can stay responsive, juggling user clicks, timers, and network responses, without truly running things in parallel. When a slow task arrives, the loop hands it off to be finished in the background and keeps working, then circles back to the result when it is ready. Here is how the event loop works, why it matters, and the one mistake that brings everything to a halt.
How the event loop works
The loop is exactly what it sounds like: a cycle that repeats forever while the program runs. On each pass, it checks a queue of pending tasks, takes the next one, runs it to completion, and then loops again. There is only one thread, so only one task runs at any instant.
The trick is what happens with slow work like reading a file or waiting on a network. Instead of standing still until that finishes, the program hands the slow task off to the system and immediately moves on to other queued tasks. When the slow work completes, its follow-up gets placed back in the queue, and the loop picks it up on a later pass. To the user, the program feels like it is doing many things at once.
If the underlying idea of concurrency is new, our explainer on what async await is shows the modern syntax built on top of this model.
Why it powers JavaScript
JavaScript runs on a single thread, which sounds limiting until you see the event loop at work. Web pages are full of waiting: waiting for a click, waiting for data to arrive, waiting for a timer. If the language froze during every wait, pages would be unusable.
| Situation |
Without an event loop |
With an event loop |
| Waiting for data |
Program freezes until it arrives |
Program keeps working, resumes later |
| Handling clicks |
Each must finish before the next |
Clicks queue and process in turn |
| Running a timer |
Blocks other work |
Fires later without blocking |
This non-blocking style is why a single-threaded language can feel smooth and concurrent. It interleaves tasks rather than truly running them side by side.
Where it trips you up
- Long synchronous work blocks the loop. Because only one task runs at a time, a heavy calculation that does not yield freezes clicks, timers, and everything else until it finishes.
- Order can surprise you. Tasks scheduled for later run after the current work and any queued items, which sometimes runs in a different order than you expect.
- It is not parallel. The event loop interleaves tasks on one thread; it does not run two pieces of your code at the same instant.
The practical rule is to keep the work you do directly on the loop short, and push anything heavy to the background so the loop stays free to respond.
Common mistakes
- Blocking the loop with heavy work. A long calculation on the main thread freezes the whole interface.
- Assuming parallel execution. The loop interleaves; it does not run your functions simultaneously.
- Misreading task order. Deferred and immediate tasks run at different times, so do not assume top-to-bottom order for async work.
- Ignoring errors in background tasks. A failure in deferred work can be silently lost if you do not handle it.
FAQ
Is the event loop multithreaded?
No. The event loop runs on a single thread and processes one task at a time. Slow work is offloaded, but your code is interleaved, not run in parallel.
Why does my page freeze sometimes?
Usually a long synchronous task is blocking the event loop. Break the work into smaller pieces or move it off the main thread so the loop can keep responding.
Is the event loop only in JavaScript?
No. The pattern appears in many systems and languages, but it is most associated with JavaScript because the language relies on it so heavily.
How does async await relate to the event loop?
Async await is friendlier syntax for scheduling work that completes later. Under the hood, those results are placed back in the queue for the event loop to pick up.
Where to go next
See the modern syntax in What Is Async Await in 2026, understand deferred results with What Is a Promise in JavaScript in 2026, and sharpen your skills via How to Debug JavaScript in 2026.