Async JavaScript and Fetch
Modern web apps talk to APIs. Async JavaScript lets the page stay responsive while requests are running.
Promises
A promise represents work that will finish later: successful, failed, or still pending.
async/await
async function loadUser(id) {
const response = await fetch(`/api/users/${id}`);
const user = await response.json();
return user;
}
Error Handling
async function loadOrders() {
const response = await fetch("/api/orders");
if (!response.ok) {
throw new Error(`Request failed: ${response.status}`);
}
return response.json();
}
What QA Should Check
- Loading state appears while the request is pending.
- Error message appears when API fails.
- Empty state appears when API returns no records.
- UI uses the correct response fields.