The setInterval () method will continue calling the function until clearInterval () is called, or the window is closed. You have to store the timer id of the interval when you start it, you will use this value later to stop it, using the clearInterval function: This is based on CMS's answer. Why are non-folding tyres still manufactured? In this way, we can use the setInterval() method of window scope object for repetitively executing a certain functionality after a certain time interval. You can do this the same way you stop timeouts — by passing the identifier returned by the setInterval() call to the clearInterval() function: const myInterval = setInterval (myFunction, 2000); clearInterval (myInterval); Active learning: Creating your own stopwatch! Stopwatch script We can display a stop watch showing hour, minutes and seconds. { intervalId = setInterval(varName, 10000); var str=dt.toTimeString() clearInterval(m.interval);