0 votes
455 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 405 views
asked Apr 3, 2022 in Javascript by Doubtly (98.9k points)
0 votes
1 answer 402 views
asked Apr 3, 2022 in Javascript by Doubtly (98.9k points)
0 votes
1 answer 377 views
0 votes
1 answer 604 views
0 votes
1 answer 418 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!

Recent Badges

HelloWorld Earned a badge
CodeWithHarry Earned a badge
Doubtly Earned a badge

5.7k questions

5.1k answers

108 comments

650 users

...