This post will discuss how to repeatedly call a function or execute the specified code in JavaScript.

1. Using setInterval() method

The following solution uses the setInterval() method to repeatedly call a function with a specified time delay between each call. To stop the timer, pass the return value of setInterval() to the clearInterval() method.

2. Using setTimeout() method

Another approach is to use the setTimeout() method, which is used to execute a function or code snippet once the specified time is elapsed. The following code example uses setTimeout() with a self-executing anonymous function.

 
The above code uses arguments.callee() to get the anonymous function’s name. ES5 forbids the use of arguments.callee() and suggest giving the function expressions a name:

That’s all about repeatedly call a function in JavaScript.