The following prints my message straight away
setTimeout(console.log('delayed hello world'), 10000);
It's a little bit counterintuitive. And since my message print straight away what happens at the end of 10 seconds?
You need to use anonymously function for that:
setTimeout(function() { console.log('delayed hello world') }, 10000);
See more about passing params to setTimeout
function at MDN
You are running console.log (because you have ()
on the end of it) and passing its return value to setTimeout
instead of passing a function.
var myFunction = function () { console.log('delayed hello world'); }
setTimeout(myFunction, 10000);