How JavaScript Promises and async/await work in two phases

🚀 JavaScript Developers — Can you predict this output? This question looks simple but tests your understanding of Promises, async/await, and the microtask queue. Why this happens JavaScript runs in two phases: 1️⃣ Synchronous (call stack) runs first firstFunction() logs 'second1' immediately. 2️⃣ Microtasks (Promise callbacks) run next .then() from firstFunction logs first "I have resolved!". Then await myPromise() in secondFunction continues and logs: "I have resolved!"  So the final order is : second1 I have resolved! I have resolved! second2 #javascript #promises #asyncawait #eventloop #frontenddevelopment #webdevelopment #reactjs #nextjs #codingtips #interviewprep #softwareengineering #womenintech #learnjavascript #jsdevelopers

  • text

then creates a promise right?

Like
Reply

Second 1 I have resolved I have resolved Second 2

Second1 I have resolved Second2 I have resolved

Second 1 I have resolved x2 Second 2

Second 1 I have resolved I have resolved Second 2

See more comments

To view or add a comment, sign in

Explore content categories