TGViewer
Web Development Web Development @webdevcoursefree · 79.7K subscribers
Post #3403 3.96K
✅ JavaScript – Fetch API, Promises Async/Await 🌐⚙️

These are essential for handling API calls and asynchronous tasks in modern JavaScript.

1️⃣ What is Fetch API?
The fetch() method is used to make HTTP requests.
It returns a Promise that resolves to the response.

fetch("https://api.example.com/data")
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error("Error:", error));


▶️ This fetches JSON data from a URL and logs it.

2️⃣ What is a Promise?
A Promise represents a value that may be available now, later, or never.
It has 3 states: pending, resolved, rejected.

const myPromise = new Promise((resolve, reject) => {
setTimeout(() => resolve("Success!"), 2000);
});

myPromise.then(res => console.log(res));


▶️ Logs “Success!” after 2 seconds.

3️⃣ Async/Await
A cleaner way to handle Promises using async and await.

async function getData() {
try {
const res = await fetch("https://api.example.com/data");
const data = await res.json();
console.log(data);
} catch (error) {
console.error("Error:", error);
}
}

getData();


▶️ Same as fetch + then, but more readable using try/catch.

🧠 Practice Task:
✅ Make a fetch request to a public API
✅ Convert it using async/await
✅ Handle errors using try...catch

💬 Tap ❤️ for more
  • ❤ 8
  • 👍 1
  • 👏 1
More from @webdevcoursefree
  1. Oct 16, 2026𝗗𝗮𝘁𝗮 𝘀𝗰𝗶𝗲𝗻𝗰𝗲 𝗖𝗲𝗿𝘁𝗶𝗳𝗶𝗰𝗮𝘁𝗶𝗼𝗻 𝗪𝗶𝘁𝗵 𝗔𝗜😍 Future Ready Data Scien…
  2. Oct 16, 2026🌐 Web Development Roadmap — Part 18 HTML Lists Lists are used whenever information needs…
  3. Oct 14, 2026🌐 Web Development Roadmap — Part 17 HTML Images — <img> Tag Images make webpages more vis…
  4. Oct 13, 2026𝗧𝗢𝗣 𝗙𝗥𝗘𝗘 𝗖𝗢𝗨𝗥𝗦𝗘𝗦 𝗧𝗢 𝗕𝗢𝗢𝗦𝗧 𝗬𝗢𝗨𝗥 𝗦𝗞𝗜𝗟𝗟𝗦 𝗜𝗡 𝟮𝟬𝟮𝟲! Explor…
  5. Oct 12, 2026For example: Go to Profile → <a> Submit Form → <button> Open Article → <a> Delete Account…
  6. Oct 12, 2026🌐 Web Development Roadmap — Part 16 HTML Links — Tag Links are one of the most important…
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook →Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 →