0 votes
487 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 417 views
asked Apr 3, 2022 in Javascript by Doubtly (98.9k points)
0 votes
1 answer 410 views
asked Apr 3, 2022 in Javascript by Doubtly (98.9k points)
0 votes
1 answer 388 views
0 votes
1 answer 618 views
0 votes
1 answer 445 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

Doubtly Earned a badge
Doubtly Earned a badge
laxman Ji Earned a badge

5.7k questions

5.1k answers

108 comments

650 users

...