๐—›๐—ผ๐˜„ ๐—๐—ฎ๐˜ƒ๐—ฎ๐—ฆ๐—ฐ๐—ฟ๐—ถ๐—ฝ๐˜ ๐—”๐˜€๐˜†๐—ป๐—ฐ ๐—ช๐—ผ๐—ฟ๐—ธ๐˜€

You struggle with Promises and async/await. You need to know what happens behind the scenes.

Learn these five things:

JavaScript runs on one thread. One piece of code runs at a time. The Call Stack tracks your functions.

Wait times create a problem. Web APIs handle timers. The browser handles the timer. The callback goes to the Task Queue.

The Event Loop checks the stack. If the stack is empty, it pushes the callback.

Promises are different. They use the Microtask Queue. Microtasks run before Tasks. Promises run before timeouts.

Async functions return Promises. Await splits your function into two parts. The second part becomes a Microtask. It runs later.

Stop awaiting every line. Sequential awaits make code slow. Start your promises first. Use Promise.all for parallel work.

Async/await are tools for the Event Loop. They control when your code runs.

Source: https://dev.to/bysontech_8dd1313811a8895/how-javascript-asynchronous-processing-actually-works-1m1d