Fetch in Practice
fetch returns a promise. Check response.ok, parse with json() and handle errors with try catch. Send data with method, headers and body.
Example
async function load() {
try {
const res = await fetch("https://jsonplaceholder.typicode.com/todos/1");
if (!res.ok) throw new Error("HTTP " + res.status);
console.log(await res.json());
} catch (e) { console.log("failed:", e.message); }
}
load();Exercise
Check success.
if (!res.)
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.