Member-only story
JavaScript clearInterval
Source: JavaScript clearInterval
For more questions and answers visit our website at Frontend Interview Questions
setInterval method sets up a recurring timer. It returns a handle that you can pass into clearInterval to stop it from firing:
JS code:-
var myVar = setInterval(myTimer, 1000);
function myTimer() {
var d = new Date();
var t = d.toLocaleTimeString();
document.getElementById("demo").innerHTML = t;
}
function myStopFunction() {
clearInterval(myVar);
}








