Learn JavaScript
Timeouts and Intervals

clearTimeout method

clearTimeout() can be used to cancel a timeout previously created using the setTimeout() method.

In the example given below, the timeout is cancelled before the time delay has elapsed. Hence, the function passed to the setTimeout() method is never run and the message is not displayed. If we remove the clearTimeout() method, then the function is run normally after a delay of 3 seconds.

As can be seen from the example given above, the clearTimeout() method takes only one parameter: the identifier value returned when calling the setTimeout() method.