a demo for setInterval() and clearInterval()
let timer;
let count = 0;
function start() {
timer = setInterval(() => {
console.log(count++);
}, 1000);
}
function stop() {
clearInterval(timer);
}
start();
setTimeout(stop, 3000);
setTimeout(start, 1000);