Advertisement
728x90
The clearInterval() function is used in javascript to clear the interval which has been set by setInterval() function. i.e, The return value returned by setInterval() function is stored in a variable and it’s passed into the clearInterval() function to clear the interval.
For example, the below setInterval method is used to display the message for every 3 seconds. This interval can be cleared by the clearInterval() method.
javascript
1<script>
2 var msg;
3 function greeting() {
4 alert('Good morning');
5 }
6 function start() {
7 msg = setInterval(greeting, 3000);
8
9 }
10
11 function stop() {
12 clearInterval(msg);
13 }
14 </script>Advertisement
Responsive Ad
🎯 Practice NowRelated Challenge
JavaScript Coding Exercise 35
Test your knowledge with this interactive coding challenge.
Start CodingAdvertisement
728x90
119of476