5 lines
199 B
JavaScript

// repeat with the interval of 2 seconds
let timerId = setInterval(() => console.log('tick'), 2000);
// after 5 seconds stop
setTimeout(() => { clearInterval(timerId); console.log('stop'); }, 5000);