// Execute function after 1 second:But this kind of anonymous timer cannot be stopped (short of reloading the entire page).
setTimeout( "doSomething()", 1000 );
var tmr = setTimeout( "doSomething()", 1000 );
var tmr1 = setTimeout( "alert('Reached first timer!')", 1000 );If you ran the code above, you noticed that the first timer was cleared before it got a chance to reach its time limit; but the second timeout (whose variable wasn't passed) worked just fine.
var tmr2 = setTimeout( "alert('Second timer reached!')", 1500 );
clearTimeout( tmr1 ); // Click over there to test this code ->
• setTimeout() starts a single countdown timer, cancellable by clearTimeout() before it expires.
• setInterval() launches a series of recurring timers that run until stopped with clearInterval().