Unfortunately JavaScript is one of those languages that has lots of "never or rarely use this" cases
Unfortunately JavaScript is one of those languages that has lots of "never or rarely use this" cases
Usually you want a recurring task that start after the previous invocation finished. Recursive setTimeout is the straight forward choice, while setInterval may require you to cancel the interval, making you just reimplementing setTimeout.
Scheduling task in setInterval will run the task every interval time set regardless the previous task has finihsed or not. This in turn will starve your hardware if the function could not finish before the next execution begin.
That only applies to async work performed inside the callback. Once the CPU is starved, or if the work performed inside the callback takes longer than the interval, then setInterval will start to skip.