CodeZettaInterview Hub

JavaScript · Event Loop · Fresh / Intern · Concept

What is the JavaScript event loop?

Short Interview Answer

The event loop coordinates the call stack, task queues, and microtask queue so async callbacks run after synchronous code finishes.

Detailed Explanation

While the call stack is empty, the event loop takes the next task (macrotask) from the appropriate queue and runs it to completion. Between tasks (and after each task), it drains the microtask queue (promise jobs, queueMicrotask, MutationObserver). Browser and Node have similar conceptual models with host-specific task sources (UI events, timers, I/O). The event loop enables concurrency on a single thread without running JS in parallel on the main thread.

Interview Tip

Sketch stack + heap + queue — visual answers stick.

Common Mistake

Saying the event loop is a separate thread that executes your JS.

Did you know this answer?