SetTimeout Minimum Delay
Multiple Choice Medium
Question
What is the minimum delay for setTimeout in browsers?
Hint
setTimeout(fn, 0) does not execute immediately.
Explanation
setTimeout(fn, 0) queues the callback as a macrotask, which executes after the current call stack and all microtasks complete. Modern browsers clamp nested setTimeout calls to a minimum of 4ms after 5 levels of nesting. For immediate execution after microtasks, use queueMicrotask() or Promise.resolve().then().
Related Resources
Related Lessons
- Async JavaScript
Learn async JS.
Look up unfamiliar terms
A beginner-friendly glossary explains jargon in plain English — variables, functions, DOM, Promise, and more.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.
Build real projects
Apply what you learned by building guided projects with starter code and solutions.