Learn how setInterval() method works here

The JavaScript setInterval() method is a method from the DOM Window object that allows you to run a specific function at a defined interval.

For example, the following fnLog() function will be executed every 1 second:

let timer = setInterval(fnLog, 1000);

function fnLog() {
  console.log("Function fnLog executed");
}

The setInterval() method requires two parameters:

  • The function to execute
  • The number interval, specifying how often you want to execute the function. The number interval is in milliseconds, so 1000 equals to 1 second.

#javascript

JavaScript setInterval() Method Explained
1.75 GEEK