A Promise is a JavaScript object representing the eventual completion or failure of an asynchronous operation. It allows you to attach callbacks after the fact — removing the need for nesting. Promise States A Promise is always in one of three states: Pending (initial state — the operation is in progress), Fulfilled (the operation completed successfully — .then() is called), or Rejected (the operation failed — .catch() is called). Once settled (fulfilled or rejected), a Promise's state never changes. Creating & Consuming Promises Creating a Promise: new Promise((resolve, reject) => { ... }). Call resolve(value) on success and reject(error) on failure. The .then(onFulfilled, onRejected) method handles both. Chain .then() calls for sequential steps — each .then() returns a new Promise…
Key Takeaways
Three states: Pending → Fulfilled or Rejected (never reverses).
Chain .then() for success, .catch() for errors, .finally() for cleanup.
Each .then() returns a new Promise — enabling chaining.
Promise.all() runs parallel requests; fails fast if one rejects.
Promise.allSettled() gets ALL results even if some fail.