Promise Di JavaScript
const API_URL = "https://jsonplaceholder.typicode.com/todos/1";
function getData(url) {
return new Promise((resolve, reject) => {
fetch(url)
.then((res) => res.json())
.then((data) => resolve(data))
.then((err) => reject(err));
});
}
getData(API_URL)
.then((data) => {
console.log("Data Diterima: ", data);
})
.catch((error) => {
console.log("Terjadi Error: ", error);
});