clearInterval
Cancels a timed, repeating action which was previously established by a call to setInterval()
Syntax
clearInterval(intervalID)Parameters
| Parameter | Type | Description |
|---|---|---|
| intervalID | number | The identifier of the repeated action to cancel |
Return Value
undefined
Examples
const id = setInterval(() => console.log('tick'), 1000);
setTimeout(() => clearInterval(id), 5000);let intervalId: ReturnType<typeof setInterval> | null = null;
function startPolling() {
intervalId = setInterval(fetchData, 3000);
}
function stopPolling() {
if (intervalId) clearInterval(intervalId);
}const counter = { id: setInterval(() => {}, 100) };
clearInterval(counter.id);
console.log('Interval stopped');Understanding clearInterval
The clearInterval method in JavaScript cancels a timed, repeating action which was previously established by a call to setInterval(). It belongs to the window object and is one of the most widely used methods for working with window values in modern JavaScript and TypeScript applications.
The method signature is clearInterval(intervalID). It accepts 1 parameter: intervalID. When called, it returns undefined. Understanding when and how to use clearInterval() helps you write more expressive, readable code.
Common use cases for clearInterval include data transformation, input validation, API response processing, and building reusable utility functions. It works well alongside related methods like window-setinterval, window-cleartimeout, window-settimeout, enabling you to chain operations together for complex data manipulation pipelines.
Browser support for clearInterval is excellent across all modern browsers including Chrome, Firefox, Safari, and Edge. It is also fully supported in Node.js and Deno. For older environments, transpilation with Babel or a polyfill may be needed.
Browser Compatibility
Supported in all modern browsers (Chrome, Firefox, Safari, Edge) and Node.js. Part of the ECMAScript standard.
Related Methods
More Global / Window Methods
Other methods in the Global / Window object
Related Tools
More Global / Window Methods
Explore JavaScript Methods
Browse our complete reference of 410 JavaScript methods with syntax, examples, and explanations.