0

setTimeout vs setInrerval?

Hello guys, I actually wanna know this what's the difference between setTimeout and setInterval in JS?

28th Nov 2021, 8:17 AM
Adarsh Addee
Adarsh Addee - avatar
2 Answers
+ 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.
28th Nov 2021, 9:05 AM
Arun Jamson
Arun Jamson - avatar
+ 1
Thank you
28th Nov 2021, 9:29 AM
Adarsh Addee
Adarsh Addee - avatar