JavaScript Event Loop Visualizer

Step through JavaScript code and see exactly how the event loop processes the call stack, microtask queue, callback queue, and Web APIs in real time.

Examples:
Ready
5x
Load an example or enter code and press Step to begin.
Call Stack
Web APIs
Microtask Queue
Callback Queue
Console Output

Frequently Asked Questions

What is the JavaScript event loop?
The event loop is the mechanism that allows JavaScript to perform non-blocking operations despite being single-threaded. It continuously checks the call stack and task queues, executing callbacks when the stack is empty. This is what enables asynchronous behavior in JavaScript.
What is the difference between the microtask queue and the callback queue?
The microtask queue (used by Promises and queueMicrotask) has higher priority than the callback queue (macrotask queue, used by setTimeout and setInterval). After each task completes, ALL microtasks are drained before the next macrotask runs. This is why Promise.then() callbacks execute before setTimeout callbacks even with a 0ms delay.
Why does setTimeout(fn, 0) not execute immediately?
Even with a 0ms delay, setTimeout schedules the callback as a macrotask in the callback queue. It must wait for the current synchronous code to finish, all microtasks to be drained, and its turn in the macrotask queue. The minimum delay in browsers is typically 4ms due to clamping.
How does async/await relate to the event loop?
async/await is syntactic sugar over Promises. When an await expression is encountered, the code after the await is wrapped in a .then() callback and placed in the microtask queue. The async function effectively yields control back to the caller, and resumes when the awaited promise resolves.
What is microtask starvation?
Microtask starvation occurs when microtasks keep scheduling more microtasks, preventing the event loop from ever reaching the macrotask queue. Since ALL microtasks must drain before any macrotask runs, this can block setTimeout callbacks, rendering updates, and user interactions indefinitely.