Home

clearTimeout

clearTimeout is a global JavaScript function used to cancel a timer created with setTimeout. It is provided by browser environments and by Node.js as part of the core timer APIs. The function takes a single parameter, timerId, which is the value returned by a previous call to setTimeout. If clearTimeout is invoked before the timer’s callback has executed, the scheduled function will not run. If the timer has already fired, or if the timer has been previously cleared, calling clearTimeout has no effect. The function returns undefined.

Most commonly you store the return value of setTimeout and later decide to cancel it based on

In modern environments, the timer identifier may be a number or an object; pass whatever setTimeout returned.

Example: var id = setTimeout(function() { console.log('Hello'); }, 1000); clearTimeout(id);

See also: setTimeout, setInterval, clearInterval.

user
actions
or
other
conditions.
Note
that
for
repeating
timers
created
with
setInterval,
the
corresponding
cancellation
function
is
clearInterval
(which
accepts
the
same
type
of
timer
id).
Some
environments
may
also
accept
clearTimeout
for
interval
timers,
but
the
standard
approach
is
to
use
clearInterval.