Mastering the JavaScript Event Loop: 5-Queue Step-by-Step Execution
Step through synchronous stack execution, microtask checkpoints, animation frames, macrotasks, and idle callbacks to see the exact order of console.log outputs in real time.
Frequently Asked Questions (FAQ)
Q1 Why do Microtasks (Promise.then) always run before Macrotasks (setTimeout)?
Whenever the JavaScript Call Stack becomes empty, the runtime immediately performs a Microtask Checkpoint—draining every queued microtask (including newly spawned ones) until the Microtask Queue is completely empty before moving on to rendering or dequeuing a single macrotask.
Q2 When do requestAnimationFrame and requestIdleCallback execute?
requestAnimationFrame runs right before the browser repaints the screen (typically every 16.6ms on a 60Hz display), whereas requestIdleCallback runs only during idle periods at the end of a frame when both microtask and macrotask queues are empty.