JavaScript Timing Functions – setTimeout, setInterval tutorial

JavaScript is very popular interactive web development scripting language used in 100% websites around WWW. JavaScript can be executed at different time intervals. This is called timing events.

JavaScript is used in each website these days for various interactive functionality. Some times we need some activity within some specified time or some intervals. So with JavaScript it is possibles to execute some functions as some specific intervals. For example , we want to refresh out website on each 5 min so we can have this by using java script timing functions.

The 2 method can be used for timing events –

1- setIterval() – it executes some events, over and over again some specified intervals.

window.setInterval("javascript function", milliseconds);

window.setInterval() method can written without window prefix but first parameter of set interval should be a function. The second parameter indicated the time in milliseconds, on each time intervals this function called again and again.

2- setTimeout()– it executes some events, after some waiting time in milliseconds. This functions is only called once.


1000 ms = 1 sec

In this function will be called after some specified milliseconds. Both parameters are require d in set Timeout .

You can use the function clearTimeout() to cancel the setTimout() timer.

Leave a Reply