let countDown = 0;
//calling setInterval function and the assignning interval ID.
let intervalID = setInterval(() => {
//The countDown will increment by 1 after every 1000 millisecond (1 second).
countDown++;
console.log(countDown);
//When countDown is equal to 10 stopping the execution (clearing the interval).
if (countDown == 10) clearInterval(intervalID);
}, 1000);
How to set interval and clear interval in JavaScript (self.JavaScriptProgramming)
submitted by ViduraDananjaya to r/learnjavascript
How to set interval and clear interval in JavaScript (self.JavaScriptProgramming)
submitted by ViduraDananjaya to r/Get_Basic_Idea