according to MDN
var timeoutID = window.setTimeout(func, [delay, param1, param2, ...]);
var timeoutID = window.setTimeout(code, [delay]);
as you can see:
setTimeout(function() {
alert(2);
}, 0);
alert(1);
the result is fristly '1' and then '2'.
setTimeout(alert(2), 0);
alert(1);
however,the result is fristly '2' and then '1'.
what causes the difference?