clearTimeout()
clearTimeout()
is a window method that stops a previously scheduled setTimeout()
from running.
Syntax
clearTimeout(timeoutID);
The clearTimeout()
function receives a timeout ID as its argument, which is returned by the corresponding call of setTimeout()
, and cancels its execution.
Example
Below is a example of how clearTimeout()
works.
const timeoutID = setTimeout(() => {console.log('This will be canceled and it will not run.');}, 3000);// clearTimeout() will cancel the timeout when invokedclearTimeout(timeoutID);
In the example above, a setTimeout()
is invoked allowing to schedule the execution of that function after the 3-second delay (3000ms). However, to cancel that schedule timeout before it runs, the clearTimeout()
is called, passing the timeout ID.
Looking to contribute?
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.