Hello Dev Community! 👋
It is officially Day 29 of my journey to master the MERN stack! Tomorrow marks a full month of consistency, and today I wrapped up the absolute final part of Lecture 10 in Apna College's JavaScript playlist with Shradha Didi. We focused on the modern industry standard for asynchronous execution: Async/Await and IIFE.
Yesterday, we flattened our code using Promise Chaining. Today, I learned the syntax that senior developers use daily to make async operations read like simple, linear code.
🧠 Key Learnings From JS Lecture 10 (Async/Await)
Async/Await is not a new concept under the hood; it is a beautiful syntax wrapper (syntactic sugar) built on top of native Promises.
1. The async & await Keywords
-
async: Placed before a function declaration, it automatically forces that function to return a Promise. -
await: Can only be used inside anasyncfunction. It pauses the function's execution line-by-line until the target Promise resolves or rejects.
This completely eliminates the need for chaining .then() blocks! Look how clean this layout is:
javascript
async function getAllData() {
await getData(1);
await getData(2);
await getData(3);
console.log("All data fetched linearly!");
}
For further actions, you may consider blocking this person and/or reporting abuse
