I executed the following code:
setTimeout(() => console.log('first'), 0)
console.log('second');
and as expeted got the output (since Javascript acts asynchronously) in the following order:
second
first
But when I changed the first argument of the setTimeout()
function like so:
//notice the ()=> part is removed
setTimeout(console.log('first'), 0)
console.log('second');
I get the output in the following order:
first
second
It is as if Javascripts starts behaving synchronously again after I removed the ()=>
part of the first argument.
Can someone explain this?