JavaScript · Middle · Question 25 of 75
Why is a recursive setTimeout sometimes preferable to setInterval?
- ✓Correct answer: It guarantees a pause between the end of one run and the start of the next
- 2It runs in a separate thread and doesn't block the UI
- 3It doesn't depend on the event loop and always fires exactly on time
Explanation
setInterval schedules runs on a fixed timetable: if a task (like a request) takes longer than the interval, calls overlap. A recursive setTimeout schedules the next run after the current one finishes and lets you vary the delay. Both timers are imprecise and depend on thread load.