clearInterval()

Cancels a repeating timer previously created with setInterval().

Since ES1 Spec ↗

Syntax

clearInterval(intervalId)

Returns

undefined — Returns `undefined`.

Examples

let count = 0;
const id = setInterval(() => {
  if (++count === 2) {
    clearInterval(id);
    console.log("stopped");
  }
}, 10);
Output
stopped

Notes

- Passing an invalid id is a harmless no-op. - Always store the interval id so it can be cleared later.

Browser & runtime support

EnvironmentSince version
chrome 1.0
firefox 1.0
safari 1.0
edge 12
node 0.10

See also