How to use setInterval function call in JavaScript?

JavascriptWeb DevelopmentFront End Technology

The setInterval() method is JavaScript is used to evaluate an expression at intervals. Here’s the syntax:

setInterval(function, interval_in_milliseconds, param1, param2, param3...)

Here, interval_in_milliseconds sets the intervals in milliseconds, after the code will execute.

param are the optional parameters, which is passend to the function.


You can try to run the following code to use setInterval() function call

Live Demo

<!DOCTYPE html>
      <p id="test"></p>
         var myVar = setInterval(function(){ displayTimer() }, 500);
         function displayTimer() {
            var date = new Date();
            var time = date.toLocaleTimeString();
            document.getElementById("test").innerHTML = "Time: "+time;
Updated on 07-Jan-2020 09:36:43