Cooperative asynchronous JavaScript: Timeouts and intervals

Introduction

For a long time, the web platform has offered JavaScript programmers a number of functions that allow them to asynchronously execute code after a certain time interval has elapsed, and to repeatedly execute a block of code asynchronously until you tell it to stop.

These functions are:

setTimeout()Execute a specified block of code once after a specified time has elapsed.setInterval()Execute a specified block of code repeatedly with a fixed time delay between each call.requestAnimationFrame()The modern version of setInterval(). Executes a specified block of code before the browser next repaints the display, allowing an animation to be run at a suitable framerate regardless of the environment it is being run in.

Take a look https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Asynchronous/Timeouts_and_intervals for better understanding about Timeouts and intervals.

Last updated