Answers

Question and Answer:

  Home  Expert JavaScript Developer

⟩ What does a timer do and how would you implement one?

Setting timers allows you to execute your code at predefined times or intervals.

This can be achieved through two main methods: setInterval(); and setTimeout();

setInterval() accepts a function and a specified number of milliseconds.

ex) setInterval(function(){alert("Hello, World!"),10000) will alert the "Hello, World!" function every 10 seconds.

setTimeout() also accepts a function, followed by milliseconds. setTimeout() will only execute the function once after the specified amount of time, and will not reoccur in intervals.

 225 views

More Questions for you: