JavaScript · Middle · Question 25 of 75

Why is a recursive setTimeout sometimes preferable to setInterval?

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.

Further reading

Problem with a question

JavaScript · Middle · question 25

Test yourself

Take the JavaScript · Middle quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz