Facebook Pixel

Can you trust setTimeout to run exactly after the specified delay?

No. setTimeout guarantees a minimum delay, not an exact delay. The actual delay depends on the call stack, microtask queue, background tab throttling, and nested timer clamping. The callback runs at least after the delay, but often later.

Verify This Answer

Cross-check this information using these trusted sources:

More FAQs in Trust Issues With setTimeout in JavaScript

Because the callback goes to the macrotask queue. The event loop runs it only when the call stack is empty and all microtasks are done. If synchronous code or microtasks are running, the timer waits.

Yes. To save battery, browsers throttle timers in background tabs. A setTimeout(cb, 100) in a background tab might run after 1000ms or later. Do not rely on timers for background tabs.

requestAnimationFrame. It syncs with the browser's refresh rate (usually 60fps) and runs the callback before the next paint. It is smoother and more efficient than setTimeout for visual updates.

Still have questions?

Browse all our FAQs or reach out to our support team

Want to upskill yourself?

Our courses are taking a Coffee break, but your curiosity shouldn't. Stay engaged with namastedev linkedin, youtube, discord and other resources while you wait.

0
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.