Facebook Pixel
setTimeout Interview Questions: Trust Issues in JavaScript

Can a setTimeout callback run before the specified delay?

The answer

No. The callback never runs before the delay. It may run later (if the stack is busy, microtasks are queued, or the tab is in the background), but never earlier.

More FAQs in setTimeout Interview Questions: Trust Issues in JavaScript

No. It guarantees a minimum of 1000ms. The actual delay depends on the call stack, microtask queue, background tab throttling, and nested timer clamping. The callback runs at least after 1000ms, but often later.

4ms after 5 nested levels. The HTML spec specifies this to prevent abuse. The first 5 levels can use 0ms, but after that, the delay is clamped to 4ms.

The delay is treated as 0. The callback goes to the macrotask queue and runs after the call stack is empty and all microtasks are done.

Still have questions?

Browse all our FAQs or reach out to our support team

Want to upskill yourself?

Your learning library

Small steps. Big possibilities.

Find your next course. Build something great.

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.
Please Login.
Please Login.
Please Login.