Expert Developer JavaScript Question:

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

Answer:

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.

Download Expert JavaScript Developer PDF Read All 150 Expert JavaScript Developer Questions
Previous QuestionNext Question
What is Push() method in JavaScript?What is the difference between JavaScript and JScript?