Tutorial by Examples

function waitFunc(){ console.log("This will be logged every 5 seconds"); } window.setInterval(waitFunc,5000);
window.setInterval() returns an IntervalID, which can be used to stop that interval from continuing to run. To do this, store the return value of window.setInterval() in a variable and call clearInterval() with that variable as the only argument: function waitFunc(){ console.log("This wil...
window.setTimout() returns a TimeoutID, which can be used to stop that timeout from running. To do this, store the return value of window.setTimeout() in a variable and call clearTimeout() with that variable as the only argument: function waitFunc(){ console.log("This will not be logged a...
To repeat a function indefinitely, setTimeout can be called recursively: function repeatingFunc() { console.log("It's been 5 seconds. Execute the function again."); setTimeout(repeatingFunc, 5000); } setTimeout(repeatingFunc, 5000); Unlike setInterval, this ensures that t...
setTimeout Executes a function, after waiting a specified number of milliseconds. used to delay the execution of a function. Syntax : setTimeout(function, milliseconds) or window.setTimeout(function, milliseconds) Example : This example outputs "hello" to the console after 1 secon...
Standard You don't need to create the variable, but it's a good practice as you can use that variable with clearInterval to stop the currently running interval. var int = setInterval("doSomething()", 5000 ); /* 5 seconds */ var int = setInterval(doSomething, 5000 ); /* same thing, no qu...

Page 1 of 1