var myVar;
function myFunction() {
myVar = setTimeout(function(){ alert("Hello"); }, 3000);
}
function myStopFunction() {
clearTimeout(myVar);
}
var timer;
function endAndStartTimer() {
window.clearTimeout(timer);
var millisecBeforeRedirect = 10000;
timer = window.setTimeout(function() {
alert('Hello!');
}, millisecBeforeRedirect);
}
clearTimeout(intervalID);
// program to stop the setTimeout() method
let count = 0;
// function creation
function increaseCount(){
// increasing the count by 1
count += 1;
console.log(count)
}
let id = setTimeout(increaseCount, 3000);
// clearTimeout
clearTimeout(id);
console.log('setTimeout is stopped.');
The clearTimeout() method of the WindowOrWorkerGlobalScope mixin cancels a timeout previously established by calling setTimeout().