I'm new to Javascript and trying to understand async programming. So I wrote the below code in chrome developer tools workspace -
console.log("hi1");
setTimeout(console.log("hi-async"),1000);
console.log("hi3");
The out put I was expecting was -
hi1
hi3
hi-async
Instead, the console printed following, without the 1 second delay (all at once) -
hi1
hi-async
hi3
So basically, the setTimeout function was executed synchronously! Can someone tell me why that's the case? I thought setTimeout is an async function and will always be executed asynchronously. Am I wrong? Thanks!