[2821 views]
setInterval() function is used in Javascript to perform some operation after specified intervals. But sometimes there is need when we need to clear the interval in Javascript.
To clear the interval, we can use clearInterval() function of Javascript which accepts interval object as its first argument.
In the above code, we are incrementing the counter by 1, every time an interval runs and when the counter value is 3 (i.e any condition is met), we call clearInterval and pass it the intervalVar object.