window.setInterval

setTimeout — Executes a code snippet or a callable repeatedly, with a fixed time delay between each call.

Description

setInterval(mixed executable, [integer delay, [mixed param, …]])

Parameters

Name Description Type Default Optional
executable Callable name or code snippet. mixed No
delay Number of milliseconds to wait between execution. integer Yes
param, … All following parameters will be passed to the callable. mixed Yes

Return values

Returns the id of the current interval.

This id can later be used with: clearInterval.

Notes

setInterval can run into trouble if delay is too short. See recursive examples in setTimeout for a workaround in these cases.

Examples

Example #1 – setInterval example
setInterval(function (param) { console.log('Logged every one second.'); // First call is executed after the specified time. }, 1000);

See also

  • setTimeout

  • clearInterval

External references