Global / Window

clearTimeout

Cancels a timeout previously established by calling setTimeout()

Syntax

JavaScript
clearTimeout(timeoutID)

Parameters

ParameterTypeDescription
timeoutIDnumberThe identifier of the timeout to cancel

Return Value

undefined

Examples

Basic Usage
const id = setTimeout(() => {
  console.log('This will not run');
}, 5000);
clearTimeout(id);
Practical Example
let timer: ReturnType<typeof setTimeout>;
function delayedSave(data: string) {
  clearTimeout(timer);
  timer = setTimeout(() => save(data), 1000);
}
Advanced Usage
const pending = setTimeout(() => console.log('fired'), 2000);
// User cancels before it fires
clearTimeout(pending);
console.log('Cancelled');

Understanding clearTimeout

The clearTimeout method in JavaScript cancels a timeout previously established by calling setTimeout(). 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 clearTimeout(timeoutID). It accepts 1 parameter: timeoutID. When called, it returns undefined. Understanding when and how to use clearTimeout() helps you write more expressive, readable code.

Common use cases for clearTimeout include data transformation, input validation, API response processing, and building reusable utility functions. It works well alongside related methods like window-settimeout, window-clearinterval, window-setinterval, enabling you to chain operations together for complex data manipulation pipelines.

Browser support for clearTimeout 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.