How is this a general question for beginners; I just wanted to emphasize that for best practice, setInterval should and can usually be avoided by using setTimeout recursively inside a function.
For instance:
var timer = 5, el = document.getElementById('countdown'); (function t_minus() { 'use strict'; el.innerHTML = timer--; if (timer >= 0) { setTimeout(function () { t_minus(); }, 1000); } else {
source share