What is JS timing

Asked 19-Jul-2021
Viewed 420 times

1 Answer


0

The window timing object allows the execution of code at specified time intervals. These time intervals are called time events. JavaScript is a Single Threaded Language. That is, only one code can be interpreted at a time, but it provides us with two such facilities, Timeouts and Intervals, using which we can do the scheduling of the execution of our codes. There are two major methods of experimenting with JavaScript.

  1. setInterval()
  2. setTimeout()

Timeout is a feature in which our JavaScript code is automatically executed after a specified amount of time. Whereas with the Intervals facility, we can execute a code repeatedly at the interval of a certain time period. We can use the setTimeout() method of the window object of the web browser to automatically execute a code after a certain period of time. This method accepts two arguments as parameters, where the first argument is the code that is to be executed, We can create the animation through the setInterval () method. 

Both setTimeout() and setInterval() methods return a unique ID of their own while executing. By storing this ID in a variable, those IDs are passed as parameters to the clearTimeout() or clearInterval() method. Both of these methods prevent those codes from being executed, whose ID is passed in as a parameter.