clearInterval()

noun

say it: “kleer IN-ter-vul” /klɪr ˈɪntərvəl/

A JavaScript function that stops a repeating timer made with setInterval(), using the ID that setInterval() handed back.

What is clearInterval() in JavaScript?

clearInterval() — Stops a repeating timer that setInterval() started. Pass it the ID setInterval() returned; without it, the interval keeps running until the page or program closes.

let ticks = 0;
const ticker = setInterval(() => {
  ticks++;
  console.log(`Tick ${ticks}`); // Tick 1, then Tick 2, then Tick 3
  if (ticks === 3) {
    clearInterval(ticker);
  }
}, 500);

In a sentence

  • “The Pause button calls clearInterval(), and Resume starts a new interval.”
  • “When the countdown reached zero, the timer called clearInterval() so it didn't keep going below zero.”

Level: Apprentice · More JavaScript terms at this level

Updated