Why does a Promise callback run before a setTimeout callback 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.
Verify This Answer
Cross-check this information using these trusted sources:
More FAQs in How setTimeout Works Behind the Scenes in JavaScript
It hands the timer to a Web API, continues running synchronous code, and when the timer fires, pushes the callback to the macrotask queue. The event loop runs the callback only when the call stack is empty and microtasks are done.
No. The callback goes to the macrotask queue. The event loop runs it only after the current call stack is empty and all microtasks are done. So it runs after synchronous code.
No. It guarantees a minimum delay, not an exact delay. The actual delay depends on the call stack, the microtask queue, timer throttling in background tabs, and nested timer throttling.
Still have questions?
Browse all our FAQs or reach out to our support team
