Why does a Promise callback run before setTimeout(cb, 0) in JavaScript?
Because promise callbacks go to the microtask queue, which the event loop drains completely before touching the macrotask queue where setTimeout callbacks live. Microtasks always run before macrotasks, regardless of delay.
Verify This Answer
Cross-check this information using these trusted sources:
More FAQs in setTimeout with Zero Delay Explained
No. The callback goes to the macrotask queue. The event loop runs it only after the call stack is empty and all microtasks are done. So it runs after the current synchronous code, not immediately.
Deferring work to keep the UI responsive, breaking long tasks into chunks (so the browser can render between chunks), and allowing the browser to paint a UI update before a heavy task blocks the thread.
Yes. After 5 nested levels, browsers may throttle setTimeout to a minimum of 4ms. In background tabs, timers are often throttled to 1 second minimum. This prevents abuse.
Still have questions?
Browse all our FAQs or reach out to our support team
