Web APIs

setInterval()

Try the free JavaScript compiler

Schedules repeated callbacks subject to host scheduling. Stop the repeating timer when no longer needed. Callback count does not guarantee exact elapsed time.

Formal Syntax & Structure

javascript syntaxjavascript
setInterval(callback, delay, ...args)

Parameters & Attributes

NameTypeDescription
callbackfunctionRepeated callback.
delaynumberRequested interval in milliseconds.
argsany[]Callback arguments.

Return Value

host-specific handle

Handle for the interval.

Working Example

Example Snippetjavascript
let count=0; const id=setInterval(()=>{console.log(++count); if(count===2) clearInterval(id);},1);
JavaScript Reference