This article will show some simple ways in which the setInterval() method can be made to execute the function without delay. There are many procedures to do so, below all the procedures are described with the example.
Note: In this article setInterval() method will start immediately for the 1
Below examples illustrate the above approach:
Example 1: Here, the setInterval() method is returned in gfg() function. The gfg() function trigger itself for subsequent calls using setTimeout() instead. Multiply the output each time in this method.
Example 2: This can be implemented using immediately invoked function expressions (IIFE) . It defines the function gfg() and calls in one go. Multiply the output each time in this method.
Example 3: The simplest way is calling the gfg() first and then starting the setInterval’s cycle of execution.
In all the above code, the first time “Hello! geeks for geeks” statement will be displayed immediately followed by the second and third and so on with a time interval of 3 seconds. The first time gfg() will be called immediately after running the code.
Note: All the above examples can be tested by typing them within the script tag of HTML or directly into the browser’s console.
- Java Script | setTimeout() & setInterval() Method
- jQuery | trigger() Method
- Difference between Trigger and Procedure in DBMS
- Trigger a keypress/keydown/keyup event in JS/jQuery
- How to trigger onchange event on input type=range while dragging in Firefox ?
- For loop in R
- R - while loop
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.