Is a fetch .then callback a microtask or macrotask in JavaScript?
Microtask. fetch returns a promise. The .then callback goes to the microtask queue. The event loop drains all microtasks before any macrotask, so fetch callbacks run before setTimeout callbacks.
Verify This Answer
Cross-check this information using these trusted sources:
More FAQs in setTimeout, fetch, and Promises With the Event Loop in JavaScript
Macrotask. setTimeout callbacks go to the macrotask queue. The event loop runs them only after the call stack is empty and all microtasks are done. This is why setTimeout runs after promise callbacks.
Microtask. Promise.then, .catch, and .finally callbacks go to the microtask queue. The event loop drains all microtasks before any macrotask. This is why promises always run before setTimeout.
Sync code runs first on the call stack. Then all microtasks (promise callbacks, fetch .then). Then one macrotask (setTimeout callback). Then microtasks again. This repeats.
Still have questions?
Browse all our FAQs or reach out to our support team
