clearInterval()
Cancels a repeating timer previously created with setInterval().
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
| Environment | Since version |
|---|---|
| chrome | 1.0 |
| firefox | 1.0 |
| safari | 1.0 |
| edge | 12 |
| node | 0.10 |