🚨 JavaScript Async Interview Question What will be the output? async function test() { console.log("1"); setTimeout(() => { console.log("2"); }, 0); await Promise.resolve(); console.log("3"); } console.log("4"); test(); console.log("5"); This question tests understanding of: • Call Stack • Async/Await behavior • Microtask queue (Promises) • Macrotask queue (setTimeout) • JavaScript Event Loop Many developers get the order wrong the first time. What do you think the output will be? #JavaScript #FrontendInterview #AsyncJavaScript #EventLoop #ReactJS #FrontendDeveloper #ProductBasedCompany
4 -> 1 -> 5 -> 3 -> 2
4->1->5->3->2
41532
Hint: After await, the remaining code runs as a microtask, which executes before macrotasks like setTimeout.