What is the event loop in JavaScript?

Understand how the JavaScript event loop handles asynchronous operations and manages concurrency.

intermediateIntermediate conceptsjavascriptevent loopconcurrency
Published: 11/3/2025
Updated: 11/3/2025

Question

What is the event loop in JavaScript?


Answer

The event loop allows JavaScript to perform non-blocking operations, even though it runs on a single thread.

It manages:

  • Call Stack
  • Callback Queue
  • Microtask Queue
console.log('Start');

setTimeout(() => console.log('Timeout'), 0);
Promise.resolve().then(() => console.log('Promise'));

console.log('End');

Output:

Start
End
Promise
Timeout

Promises (microtasks) run before callbacks (macrotasks).

Real-World Example

Event loops power async rendering, timers, and server I/O in Node.js.

Quick Practice

Predict the output of a snippet mixing setTimeout and Promise.resolve().

Summary

The event loop orchestrates async execution — the heartbeat of JavaScript’s runtime.

Related Videos
Watch these videos to learn more about this topic
Frequently Asked Questions

Does JavaScript run multiple threads?

No. It’s single-threaded but uses asynchronous callbacks managed by the event loop.


Stay Updated

Get the latest frontend challenges, interview questions and tutorials delivered to your inbox.