Skip to content

Day 3: async / await & try...catch

Write readable asynchronous code using async and await and handle failures gracefully with try...catch.

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();
  1. Refactor a Promise chain with .then() into an async/await function.