This is the best way to do this. window.setTimeout
expects a function as its first argument.
window.setTimeout(function(){countdown(limit,--initial,period);},period);
is passing an anonymous function as the first parameter to setTimeout.
window.setTimeout(countdown(limit,--initial,period),period);
is passing the result of the executed function countdown as the first parameter to setTimeout. In your case, the result of countdown is always undefined
.
For further illustration, you could have also passed in a function to window.setTimeout like this:
var myFunc = function(){countdown(limit,--initial,period);};
window.setTimeout(myFunc, period);