Sitemap
Pravin M

Pravin M

I am a frontend developer with 10+ years of experience Blog :- https://www.frontendinterviewquestions.com

Member-only story

JavaScript clearInterval

Dec 26, 2023
Press enter or click to view image in full size
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);
}

--

--

Pravin M
Pravin M

Written by Pravin M

I am a frontend developer with 10+ years of experience Blog :- https://www.frontendinterviewquestions.com