Microtask Concept Check
Question
When are Promise .then callbacks (microtasks) executed relative to setTimeout callbacks (macrotasks)?
Hint
The event loop drains all microtasks before processing a macrotask.
Explanation
The event loop has a microtask queue (Promises, queueMicrotask) and a macrotask queue (setTimeout, setInterval, I/O). After each macrotask, the event loop drains the entire microtask queue before running the next macrotask. So all pending Promise callbacks run before the next setTimeout callback, even if the setTimeout was registered first.
Related Resources
Related Lessons
- Async JavaScript
Learn about the event loop.
Look up unfamiliar terms
A beginner-friendly glossary explains jargon in plain English — variables, functions, DOM, Promise, and more.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.
Build real projects
Apply what you learned by building guided projects with starter code and solutions.