JS Event Loop Step-by-Step Visualizer (Call Stack, Microtask, rAF, Macrotask & Idle)

Interactive state-machine sandbox visualizing JavaScript Call Stack, Promise Microtasks, requestAnimationFrame, setTimeout Macrotasks, and requestIdleCallback execution order.

🚉 Stationmaster State:Ready
Step 1 / 1
💡

Loading Rust Wasm Event Loop Engine...

📜 JavaScript Source ExecutionLine #1
1function slowAction() {
2 console.log('执行栈:慢操作执行开始');
3 requestIdleCallback(() => {
4 console.log('执行栈:requestIdleCallback');
5 });
6 setTimeout(() => {
7 console.log('执行栈:setTimeout');
8 }, 0);
9 requestAnimationFrame(() => {
10 console.log('执行栈:requestAnimationFrame');
11 });
12 Promise.resolve().then(() => {
13 console.log('执行栈:Promise');
14 });
15 for (let i = 0; i < 100000; i++) {} // 同步耗时阻塞
16 console.log('执行栈:慢操作执行结束');
17}
18slowAction();
🖥️ Console Output (Execution Order)0 logs
// Waiting for console.log execution...
🥞 Call Stack (LIFO - Single Thread)Immediate Execution
[Empty — Checking Queues]
🚄 Microtask Queue (FIFO - High Priority)Priority #1
[Queue Empty]
🎨 Animation Frame Callbacks (rAF)Before Repaint
[Queue Empty]
🚂 Macrotask Queue (FIFO - setTimeout / I/O)Priority #2
[Queue Empty]
☕ Idle Callbacks (requestIdleCallback)Lowest Priority
[Queue Empty]
💡 Recommended Developer Resources & Cost SaversPartner Links · Zero Extra Cost to You

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.