window.setInterval() repeatedly calls a function with a fixed delay between each run (MDN). It returns an interval ID — pass that ID to clearInterval() to stop. For a one-shot delay, use setTimeout().
Pass the required arguments shown below. Check return values and browser support before you rely on the result.
Syntax
Call window.setInterval. Start with this line.
JavaScript
setInterval(fn, delay, ...args)
Call
What it does
setInterval(fn, delay, ...args)
Primary signature.
window.setInterval(...)
Call with the arguments your case needs.
Built into the browser. Call window.setInterval(...) (or the global setInterval(...)) — no import required.
MDN-style: guard against starting twice; clear on stop.
JavaScript
let id = null;
let count = 0;
function start() {
if (id !== null) return;
id = setInterval(function () {
count += 1;
console.log(count);
}, 1000);
}
function stop() {
clearInterval(id);
id = null;
}
Choose. Clocks → interval; “do this later” → timeout.
Overrun tip. If work can take longer than the delay, chain setTimeout after finish.
Compatibility
Browser Support
Window.setInterval() is marked Baseline Widely available on MDN (since July 2015). It is not Deprecated, Experimental, or Non-standard. Available in browsers and workers; prefer function callbacks over string code.
✓ Baseline · Widely available
setInterval()
Repeat a callback on a fixed delay across modern browsers.
99%Core tag support
ChromeYes
Full support
EdgeYes
Full support
FirefoxYes
Full support
SafariYes
Full support
OperaYes
Full support
HTML element100% supported
Bottom line: Universal timer API. Always store the ID and clear when finished; avoid string code.
Frequently Asked Questions
It repeatedly calls a function (or code) with a fixed delay between each call (MDN). The first run happens after the delay. Store the returned interval ID so you can stop it with clearInterval().
No. MDN marks Window.setInterval() as Baseline Widely available (since July 2015). It is not Deprecated, Experimental, or Non-standard. Passing a string as code is strongly discouraged (injection / XSS risk).
A positive integer interval ID. Pass that ID to clearInterval() to stop the repeating callback.
setTimeout runs once after a delay. setInterval keeps repeating until cleared. For one-shot delays use setTimeout; for clocks and polling use setInterval (or recursive setTimeout if work can overrun the delay).
Yes. Extra arguments after the delay are forwarded: setInterval(greet, 1000, "Alex"). Or wrap the call: setInterval(() => greet("Alex"), 1000).
Intervals keep firing until cleared or the page unloads. Clear when the UI no longer needs updates to save CPU and battery.