setInterval is a global JavaScript method. It is used to execute a particular function or piece of code at regular intervals.
Tag usage
The setinterval tag is appropriate for questions involving the setInterval
method.
Implementation
The primary implementation of setInterval
receives as arguments a JavaScript function and a number indicating the number of milliseconds in the interval. Ideally, the function would run at the given interval, but this is not always the case if the execution of the function takes longer than the interval. In such a case, MDN recommends using setTimeout
instead.
The first parameter to setInterval
may also be a code string instead of an actual function, but this usage is generally not recommended for the same reasons that using eval()
is frowned upon.
References