a1exlism
3/9/2017 - 8:40 AM

a demo for setInterval() and clearInterval()

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);