Both are Javascript’s timing events.
setInterval(function(), milliseconds):
- Executes a function repeatedly, with a fixed time delay between each call to that function. (useful for countdown)
- clearInterval() takes an in-scope variable which points to the setInterval method and stops the function from looping.
setTimeout(function(), milliseconds):
- Executes a function once, after waiting a specified delay.
- clearTimeout() stops the execution, thus disabling it from running again in the future.
Notes:
- 1000 milliseconds = 1 second
Advertisements