0
setTimeout vs setInrerval?
Hello guys, I actually wanna know this what's the difference between setTimeout and setInterval in JS?
2 Réponses
+ 3
For example:
setTimeout(function() { alert('foo');}, 1000);
- waits for 1000 milliseconds, then runs the callback function (alerts 'foo') in this example
setInterval(function() { alert('foo');}, 1000);
- triggers callback every 1000 milliseconds. Meaning you'd get 'foo'-alerts every 1000 milliseconds, until you call the clearInterval-function to stop it.
+ 1
Thank you