The best of both
Promises fixed callback hell, but .then chains can still feel twisty. async and await let you write waiting code that reads like a normal recipe, top to bottom.
await inside async
const wait = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
async function cookDinner() {
console.log("Washing rice");
await wait(300);
console.log("Rice cooked");
await wait(300);
console.log("Dal cooked");
return "Dinner served 🍛";
}
cookDinner().then((msg) => console.log(msg));