Loading [MathJax]/jax/output/HTML-CSS/fonts/TeX/fontdata.js

Setting an interval function

Set an interval function executes a specific piece of code periodically every when we define so. (every 5 sec, 5 mins etc).

The function accepts 2 arguments, the first argument is a function that is going to be executed,  and the second argument is a number in milliseconds. 

For example if we put as a first argument a function that prints 'Hello World' to the console, and 1000 milliseconds as the second argument, we will eventually print a 'hello word' message to the console every second.

In order to stop executing we call the clearInterval function that accepts as an argument the name of the interval that we want to stop.

Find out the setInterval documentation here

 

Set Interval

Kostas Diakogiannis
Module by Kostas Diakogiannis, updated more than 1 year ago
No tags specified