Promises and Async/Await
Promises
represent the eventual completion or failure of an asynchronous operation.
let promise = new Promise((resolve, reject) => {
setTimeout(() => resolve("Done!"), 1000);
});
promise.then(result => console.log(result));
Async/Await
makes it easier to write readable asynchronous code.
async function fetchData() {
const data = await fetch("/api/data");
const json = await data.json();
console.log(json);
}