why doesn't setTimeout
work in this example? It runs immediately.
!function() {
'use strict';
function timeOut(str) {
setTimeout(myFuction(str) , 3000);
}
function myFuction(a) {
console.log(a);
}
timeOut("Hi"); //calling
}();
I expect myFunction
to be run with passed value after 3 seconds. I know the other way. I just want to know why this doesn't work.
The working one:
!function() {
'use strict';
function myFunction(str) {
console.log(str);
}
setTimeout(function() {
myFunction("Hello")
}, 3000);
}();