DEV Community

Cover image for Javascript Timer APIs
Anuradha Aggarwal
Anuradha Aggarwal

Posted on • Updated on • Originally published at

Javascript Timer APIs

Hello Developers!! Today we will discuss the different timers API used in Javascript

  • setTimeout
  • setInterval


It delays an operation for a certain amount of time which is passed as a parameter.

It takes two parameters:

  • a function
  • delay time in millisecond
    console.log("setTimeout in action");
}, 2000)
Enter fullscreen mode Exit fullscreen mode

In the above code snippet, it will print to the console after 2000 ms.

Now look at another example of setTimeout:-

let myFunc = (num1, num2) => {
    console.log(num1, "---", num2);

setTimeout(myFunc, 2000, 2, 3);
Enter fullscreen mode Exit fullscreen mode


If you pass more than 2 parameters in the setTimeout then this will eventually become the parameters of the myFunc.


It puts a delayed operation in a loop

    console.count("setInterval in action")
Enter fullscreen mode Exit fullscreen mode


Wrap Up!!

Thank you for your time!! Let's connect to learn and grow together.

LinkedIn Twitter


Top comments (0)