0 votes
140 views
in Javascript by (98.9k points)
edited

What is the working of timers in JavaScript?

1 Answer

0 votes
by (98.9k points)
selected by
 
Best answer

Timers are used to execute a piece of code at a set time or repeat the code in a given interval. This is done by using the functions setTimeout, setInterval, and clearInterval.

The setTimeout(function, delay) function is used to start a timer that calls a particular function after the mentioned delay. The setInterval(function, delay) function repeatedly executes the given function in the mentioned delay and only halts when canceled. The clearInterval(id) function instructs the timer to stop.

Timers are operated within a single thread, and thus events might queue up, waiting to be executed.

Related questions

0 votes
1 answer 146 views
asked Apr 3, 2022 in Javascript by Doubtly (98.9k points)
0 votes
1 answer 169 views
asked Apr 3, 2022 in Javascript by Doubtly (98.9k points)
0 votes
1 answer 135 views
0 votes
1 answer 245 views
0 votes
1 answer 126 views

Doubtly is an online community for engineering students, offering:

  • Free viva questions PDFs
  • Previous year question papers (PYQs)
  • Academic doubt solutions
  • Expert-guided solutions

Get the pro version for free by logging in!

5.7k questions

5.1k answers

108 comments

557 users

...