Home > Articles > Web Development

  • Print
  • + Share This
Like this article? We recommend

Using setInterval()

What if you need to repeat the execution of your code block at specified intervals? For this, Node has methods called setInterval() and clearInterval(). The setInterval() function is very much like setTimeout(), using the same parameters such as the callback function, delay, and any optional arguments for passing to the callback function.

A simple example of setInterval() appears below:

var interval = setInterval(function(str1, str2) {
  console.log(str1 + " " + str2);
}, 1000, "Hello.", "How are you?");

clearInterval(interval);
  • + Share This
  • 🔖 Save To Your Account