Microtask Queue
Promise callbacks (.then, .catch, async continuations) run in the microtask queue — before the next macrotask (setTimeout, setInterval) but after the current synchronous code.
Promise callbacks (.then, .catch, async continuations) run in the microtask queue — before the next macrotask (setTimeout, setInterval) but after the current synchronous code.
console.log("1 sync");
setTimeout(() => console.log("3 macrotask"), 0);
Promise.resolve().then(() => console.log("2 microtask"));
console.log("1b sync");
// Output: "1 sync", "1b sync", "2 microtask", "3 macrotask"
Microtasks flush completely before any macrotask runs — starving with microtasks blocks rendering.
More in JavaScript