async function getData(url) {
const response = await fetch(url);
if (!response.ok) throw new Error("Request gagal");
return await response.json();
}
getData("https://api.example.com/items")
.then(console.log)
.catch(console.error);
async function getData(url) {
const response = await fetch(url);
if (!response.ok) throw new Error("Request gagal");
return await response.json();
}
getData("https://api.example.com/items")
.then(console.log)
.catch(console.error);