🚀 Async/Await in JavaScript – Coding ka Desi Jugadu Tareeka! (Hinglish Style)

Vivek varshneyVivek varshney
3 min read

Intro:

Socho tum Swiggy pe order karte ho pizza 🍕
Aur app bolta hai:

“Ruko bhai, delivery boy ke aane tak poora app freeze rahega.”

🤣 Kaise feel hoga? Kharab na?

JavaScript bhi pehle aisa hi tha – callback hell, promise chains… pura kachra!
Fir aayi async/await — coding ka asli saviour!

Aaj tumhe ekdum tandoori style me samjhaata hoon:

  • Async/Await hota kya hai?

  • Kyun use karein?

  • Aur code me masala kaise daalein!

🧠 Async/Await – Kya Hai Bhai?

Simple bhaasha me:

“JavaScript se bolna – Bhai, ruk ja zara, sabar kar... jab tak kaam complete na ho jaye.”

async lagao function pe → Matlab ye bhai async kaam karega.
await lagao line pe → Matlab ye line ruk ke result ka intezaar karegi.

🍜 Syntax – Asaan aur swaadisht

async function getData() {
  let response = await fetch('https://api.example.com/data');
  let data = await response.json();
  console.log(data);
}

🧂 Samajhne ka tareeka:

  • Tumne data maanga (fetch)

  • Tumne bola — “ruk ja yaar, jab tak ye API data nahi bhejti, main aage nahi badhta.”

  • Data aaya – tumne console me serve kar diya. 😋

🔐 Error Handling – try/catch ka tadka lagao!

async function getUser() {
  try {
    let res = await fetch('https://api.example.com/user');
    let user = await res.json();
    console.log(user);
  } catch (err) {
    console.error("Kuch gadbad ho gaya bhai:", err);
  }
}

👮‍♂️ Try/Catch lagana zaroori hai — nahi to tumhara code crash-test dummy ban jayega 😅

🍕 Real-Life Example – Pizza Wala Promise

function orderPizza() {
  return new Promise((resolve) => {
    setTimeout(() => resolve("Pizza delivered! 🍕"), 2000);
  });
}

async function makeOrder() {
  console.log("Pizza order kiya...");
  let result = await orderPizza();
  console.log(result);
}

makeOrder();

🧠 Output:

Pizza order kiya...
(wait 2 seconds)
Pizza delivered! 🍕

💡 Kab Kab Use Kare Async/Await?

  • Jab API call kar rahe ho (fetch, Axios etc.)

  • Jab tumhara code promises pe based ho

  • Jab tum neend bhar ke readable code chahte ho (callback hell se bachne ke liye)

🤯 Common Mistake – dhyan do!

❌ Await ko direct function me mat likhna.
✅ Use karo sirf async function ke andar!

// Galat ❌
let res = await fetch(...);

// Sahi ✅
async function getData() {
  let res = await fetch(...);
}

🏁 Wrap-Up – Coding ka Swaad Samjha?

  • async/await = readable + manageable + async ka perfect combo.

  • Callback hell gayab, code readable, dev happy 😎

  • Pizza wala example yaad rakhna – har API call me kaam aayega.

🙌 Final Thought:

“JavaScript sirf code nahi, ek art hai – aur async/await us art ka brush hai.”

Agar pasand aaya to comment karo, share karo aur follow karo bhai!
Next blog me hum explore karenge:

“Event Loop, Call Stack aur JS ka asli circus” 🎪

0
Subscribe to my newsletter

Read articles from Vivek varshney directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Vivek varshney
Vivek varshney

Full-Stack Web Developer | Blogging About Tech, React.js, Angular, Node.js & Web Development. Turning Ideas into Code & Helping Businesses Grow!