Day 3: async / await & try...catch
Daily Objective
Section titled “Daily Objective”Write readable asynchronous code using async and await and handle failures gracefully with try...catch.
1. async / await
Section titled “1. async / await”async function loadUserData() { try { const response = await fetch('https://jsonplaceholder.typicode.com/users/1'); const user = await response.json(); console.log(user.name); } catch (error) { console.error('Failed to load user:', error.message); }}loadUserData();Daily Hands-on Practice (70%)
Section titled “Daily Hands-on Practice (70%)”- Refactor a Promise chain with
.then()into anasync/awaitfunction.