How it works
The setInterval() method repeatedly calls a function or executes a code snippet, with a fixed time delay between each call.
Syntax
- myCallback: The function to be executed.
- delay: The time, in milliseconds (thousandths of a second), the timer should delay in between executions.
- Return Value: A numeric, non-zero ID which identifies the timer created.
Warning: Zombie Intervals
Always store the returned ID. If you navigate away or stop needing the interval without calling clearInterval(id), the function will continue to run in the background, consuming memory and CPU!