setTimeout, clearTimeout
There may be business requirements to execute a certain piece of code after waiting for some time duration or after a delay setTimeout can be used in such cases, clearTimeout is simply used to clear the timer that is started.
setTimeout(() => {
yourFunction();
}, 3000);
setInterval, clearInterval
setInterval is a method that calls a function or runs some code after specific intervals of time, as specified through the second parameter.
A function or block of code that is bound to an interval executes until it is stopped. To stop an interval, we can use the clearInterval() method.
setImmediate, clearImmediate
Calling the function or execution as soon as possible.
var immediateID = setImmediate(function);
// The below code displays the alert dialog immediately.
var immediateId = setImmediate(
() => { alert('Immediate Alert');
}
clearImmediate is used for Canceling the immediate actions that were set by setImmediate().
requestAnimationFrame, cancelAnimationFrame
It is the standard way to perform animations.
Calling a function to update an animation before the next animation frame.
var requestID = requestAnimationFrame(function);
// The following code performs the animation.
var requestId = requestAnimationFrame(
() => { // animate something}
)
cancelAnimationFrame is used for Canceling the function that was set by requestAnimationFrame().
Timers
setTimeout, clearTimeout There may be business requirements to execute a certain piece of code after waiting for some time duration or after a delay setTimeout can be used in such cases, clearTimeout is simply used to clear the timer that is started.
setInterval, clearInterval setInterval is a method that calls a function or runs some code after specific intervals of time, as specified through the second parameter.
A function or block of code that is bound to an interval executes until it is stopped. To stop an interval, we can use the clearInterval() method.
setImmediate, clearImmediate Calling the function or execution as soon as possible.
clearImmediate is used for Canceling the immediate actions that were set by setImmediate().
requestAnimationFrame, cancelAnimationFrame It is the standard way to perform animations.
Calling a function to update an animation before the next animation frame.
cancelAnimationFrame is used for Canceling the function that was set by requestAnimationFrame().