xxxxxxxxxx
// Get a reference to the timeout and call wwindow.clearTimeout() on
// that refrence.
let timeoutHandle = window.setTimeout( );
window.clearTimeout(timeoutHandle);
xxxxxxxxxx
// Set a timeout
const timeoutId = setTimeout(() => {
console.log('Timeout executed');
}, 5000); // 5000ms (5 seconds)
// Later, if you want to clear the timeout:
clearTimeout(timeoutId);
xxxxxxxxxx
// Set a timeout of 5 seconds
const timeout = setTimeout(() => {
console.log("Timeout completed");
}, 5000);
// Reset the timeout to 3 seconds
function resetTimeout() {
clearTimeout(timeout);
timeout = setTimeout(() => {
console.log("Timeout completed");
}, 3000);
}
// Call the resetTimeout function to reset the timeout
resetTimeout();
xxxxxxxxxx
The clearTimeout() method of the WindowOrWorkerGlobalScope mixin cancels a timeout previously established by calling setTimeout().