- Home
- /
- Tutorials
- /
- JavaScript Tutorial
- /
- JavaScript setInterval
JavaScript Asynchronous
JavaScript setInterval
setIntervalruns a function over and over until you stop it.
It works like setTimeout but repeats.
It never stops on its own, so you must always be able to cancel it.
Example
Example
javascript
let count = 0;
const id = setInterval(function () {
count = count + 1;
console.log("tick " + count);
if (count === 3) {
clearInterval(id);
}
}, 10);