Browser - Web API - setInterval



setInterval permits to execute a function at regulier interval.

If you want to call it once, you can use the setTimeout function


  • Increment and log the variable i every 3 seconds. The intervalFunctionId is called a timerId. setTimeout uses the same timeId pool. It is used in the clearInterval function to stop the execution.
let i = 0;
intervalFunctionId = setInterval(()=>{
    if (i<10) {
        console.log("Executed after "+i*3 +" seconds");
}, 3000) // every 3 seconds
  • Stop the interval function with a setTimeout after 9 seconds.
    console.log("Interval function "+intervalFunctionId +" was cleared");
}, 9000) // after 9 seconds



clearInterval function gets the return id value of the setInterval function.

Discover More
Bootstrap Tooltip Snippet

This page shows snippets on how to handle the Boostrap tooltip
How to use the setTimeOut javascript function (in the Browser)?

setTimeOut is a web api (browser function) that wraps code in a job and executes it later. The execution of the main thread (of the code) does not stop (not blocking). In this example, we will print...
React Render Element Splittsing
React - ReactDOM.render

ReactDOM.render is the main function that renders an element into a DOM element. It will be: the root element in a single page application or another react element called a secondary root, when...

Share this page:
Follow us:
Task Runner