Are clearTimeout and clearInterval the same?

Actually I believe that we can make a fairly strong conclusion from the W3C spec (http://www.w3.org/TR/html5/webappapis.html#timers). It is not explicitly guaranteed but we have a lot of evidence that almost any reasonable implementation would have this behavior: 1) Timeouts and Intervals actually use the same underlying function: The setTimeout() method must return the value returned … Read more

Code for a simple JavaScript countdown timer?

var count=30; var counter=setInterval(timer, 1000); //1000 will run it every 1 second function timer() { count=count-1; if (count <= 0) { clearInterval(counter); //counter ended, do something here return; } //Do code for showing the number of seconds here } To make the code for the timer appear in a paragraph (or anywhere else on the … Read more