0 votes
146 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 151 views
asked Apr 3, 2022 in Javascript by Doubtly (98.9k points)
0 votes
1 answer 175 views
asked Apr 3, 2022 in Javascript by Doubtly (98.9k points)
0 votes
1 answer 143 views
0 votes
1 answer 252 views
0 votes
1 answer 133 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

561 users

...