Reference · Browser JavaScript
Event loop quick map
A one-minute recall sheet
Common examples
Runs now: synchronous statements, including the top-level script.
Microtask: Promise reactions (.then(), .catch()), and continuation after an awaited settled Promise.
Task: eligible setTimeout callback; many user event callbacks.
Browser rendering: may get an opportunity between tasks after microtasks drain.
Five-step trace
1. Run the current JavaScript to completion. 2. Queue any callbacks it schedules. 3. When the stack empties, drain microtasks, including new microtasks queued by microtasks. 4. The browser selects a runnable task. 5. After that task and its microtasks finish, repeat; rendering may happen between tasks.
Remember: a zero-delay timer is still a later task. The browser’s task queues are plural; this sheet groups them for simple traces.
Return to the short lesson and practice. Specification: WHATWG event loops.