Cheat Sheets
Event Loop · Study material
Event Loop Cheat Sheet
| Rule | Detail |
|---|---|
| Order | sync → (Node: nextTick) → microtasks → one task → microtasks → … |
| Microtasks | then/catch/finally, await, queueMicrotask, MutationObserver |
| Tasks | setTimeout, setInterval, events, I/O, setImmediate, MessageChannel |
new Promise(fn) | fn runs synchronously |
async function | sync until the first await |
setTimeout(fn, ms) | at least ms; equal delays in scheduling order |
| Microtask added by a microtask | runs in the same drain, before tasks |
| Long sync code | blocks timers, events and rendering |
| Node.js phases | timers → pending → poll → check → close |
| Main module | setTimeout(0) vs setImmediate: order not guaranteed |
| Inside I/O / timer callback | setImmediate before setTimeout(0) |