JavaScript Async Await Simplified

🟨 𝗝𝗮𝘃𝗮𝗦𝗰𝗿𝗶𝗽𝘁 𝗗𝗮𝘆 𝟰𝟲: 𝗔𝘀𝘆𝗻𝗰 & 𝗔𝘄𝗮𝗶𝘁 Some things in JavaScript take time. For example: getting data from a server. JavaScript does not stop everything and wait. That’s why we use async & await. 🔹 𝗔𝘀𝘆𝗻𝗰 async tells JavaScript: “This function may take some time.” 🔹 𝗔𝘄𝗮𝗶𝘁 await means: “Wait here until the result is ready.” 🔹 𝗦𝗶𝗺𝗽𝗹𝗲 𝗘𝘅𝗮𝗺𝗽𝗹𝗲 async function getUser() { const data = await fetch("/user"); console.log(data); } JavaScript waits for the data, then prints it. 🔹 𝗪𝗵𝘆 𝗪𝗲 𝗨𝘀𝗲 𝗜𝘁 • Makes code easy to understand • Runs code in the correct order 🔹 𝗥𝗲𝗮𝗹 𝗟𝗶𝗳𝗲 𝗨𝘀𝗲 Async & await are used when: • Loading data • Submitting forms • Calling APIs 🔹 𝗞𝗲𝘆 𝗣𝗼𝗶𝗻𝘁 Async & await help JavaScript handle slow tasks in a simple way. 💬 GitHub link in the comments #JavaScript #Day46 #100DaysOfCode #Frontend

To view or add a comment, sign in

Explore content categories