Why when passing the code (surrounded by ”) like so:
setTimeout('alert("James Blunt is bad")', 5000);
Is there the 5 second pause before showing what we all know and when passing function reference like so:
setTimeout(alert("James Blunt is bad"), 5000);
There is no pause?
If your second example, you are not passing a function.
You are calling
alertand passing its return value (and the return value ofalertis not a function).Function references don’t end in
(…)Or, with weaker browser support, pass the arguments to alert in an array as the third argument to setTimeout.: