setInterval() method can be used to repeatedly run a function at fixed time intervals.
setInterval() method has two parameters:
The function that needs to be run
The time delay in milliseconds
The example given below prints “Hello, World!” onto the console every 5 seconds.
You can also pass arguments to the function, by adding them after the first two parameters of the
setTimeout() method call.
setInterval() method is very similar to the
setTimeout() method, with the only difference being that
setTimeout() runs the function only once after the time delay, while
setInterval() runs the function repeatedly after a specified time interval.