Explanation
Promises, async/await, and fetch let your app load remote data and handle loading, success, and error states.
Code example
javascriptasync function loadUsers() {
const status = document.querySelector("#status");
status.textContent = "Loading...";
try {
const res = await fetch("https://jsonplaceholder.typicode.com/users");
if (!res.ok) throw new Error("Request failed");
const users = await res.json();
status.textContent = `Loaded ${users.length} users`;
} catch (error) {
status.textContent = error instanceof Error ? error.message : "Error";
}
}
loadUsers();Helpful resources
Exercise
Fetch a public API and render results with loading and error UI states.
