Promises & async/await
A cleaner way to handle "later"
A Promise is an object that represents a value you will get in the future — either success or failure. Think of it like a food-order token: you do not have the food yet, but you hold a promise that it is coming.
let promise = fetch("https://api.example.com/user");
promise
.then((response) => console.log("Got it!"))
.catch((error) => console.log("Failed"));
.then()→ runs when it succeeds..catch()→ runs if it fails.
async / await — the easiest way
Chaining .then() works, but async/await lets you write async code that reads like normal top-to-bottom code. This is what modern developers use.
async function getUser() {
try {
let response = await fetch("https://api.example.com/user");
let data = await response.json();
console.log(data);
} catch (error) {
console.log("Something failed");
}
}
getUser();
async→ marks a function that does async work.await→ "pause here until this Promise is done, then continue".
Read it almost like English: get the response, wait for it; turn it into data, wait for it; then log it. No nesting, no pyramid.
Why this matters
Every time an app loads data — your feed, your messages, search results — it is doing exactly this: await a request, then use the result. This single pattern is everywhere.
Promise = a future value.
async/await= write async code that reads like normal code. This is the modern standard.