The functions setTimeout() and setInterval()
appear to be very similar.
The setTimeout() function delays for a specified time
period and then triggers execution of a specified function.
Once the function is triggered the setTimeout() has finished.
You can terminate the execution of the setTimeout() before it
triggers an action by using the clearTimeout() function.
But that is just about it.
The setInterval() function also delays for a specified time before
triggering the execution of an action. Where it differs is, that
after triggering an action the command doesn't complete - it just
waits for the specified time again and then triggers the function again and again.
It continues to repeat this process of triggering the function at the
specified intervals until either the web page is unloaded or the clearInterval()
function is called.
The setInterval() function is used for many slideshow presentations.
It will execute a simple function at a set interval as long as the window
state is active.
|