I have a fiddle here
Can someone help me understand why the first setTimeout works but not on second one? Please see comments on the code.
In this case, I want to alert first I am first then after 6 seconds, it would alert Hello, sorry I am late
function iAmTakingTooLong(message1, message2, callback){
//setTimeout(function(){ alert('test'); },6000); //THIS WILL WAIT FOR 6000 MILLISECONDS
setTimeout(callback(message1+message2),6000); //THIS WILL NOT WAIT FOR 6000 MILLISECONDS
}
iAmTakingTooLong('Hello, ', 'sorry I am late!', function(fullmessage){
alert(fullmessage);
});
alert("I am first!");