Why JavaScript prints 1 3 2 4 instead of 1 2 3 4

console.log("1") Promise.resolve(console.log("3")) setTimeout(()=> console.log("4")) console.log("2") Usually answer would be 1 2 3 4 right but no It will be 1 3 2 4 At first glance it looks like create a resolved promise that logs 3. But the important detail is what happens first: JavaScript evaluates arguments to a function call before calling the function.  3 printed synchronously, immediately. #javascript #reactjs #microtask #macrotask #eventloop #developer #web #development

To view or add a comment, sign in

Explore content categories