What Are Promises in JavaScript?
A promise is a placeholder for a future value. Here is what they are, the three states, and why they replaced callbacks.
What Are Promises in JavaScript?
A promise is an object representing the eventual result of an async operation. It is a placeholder for a value that will be available in the future.
The Three States
- Pending: initial state, neither fulfilled nor rejected.
- Fulfilled: the operation succeeded; the promise has a value.
- Rejected: the operation failed; the promise has a reason (error).
A promise is pending when created. It transitions to fulfilled or rejected once (settled). It cannot change state after settling.
Basic Usage
const promise = fetch("/api"); promise .then((response) => response.json()) .then((data) => console.log(data)) .catch((err) => console.error(err)) .finally(() => console.log("done")); `` - `.then(onFulfilled)`: runs when the promise fulfills. Returns a new promise. - `.catch(onRejected)`: runs when the promise rejects (or a .then throws). - `.finally(onSettled)`: runs when the promise settles (fulfilled or rejected). ### Creating a Promise ```js const promise = new Promise((resolve, reject) => { setTimeout(() => { if (success) resolve("data"); else reject(new Error("failed")); }, 1000); }); `` The executor function (`(resolve, reject) => {}`) runs immediately. Call `resolve(value)` to fulfill, `reject(reason)` to reject. ### Why Promises Replaced Callbacks - **Once-only**: a promise settles exactly once (no inversion of control). - **Chaining**: `.then` returns a new promise, enabling flat chains. - **Single error handler**: one `.catch` handles errors from anywhere in the chain. - **Parallel**: `Promise.all`, `Promise.race`, `Promise.allSettled`. - **Async/await**: built on promises, makes code look synchronous. ### The Takeaway A promise is a placeholder for a future value. It has three states: pending, fulfilled, rejected. It settles once. Use `.then`/`.catch`/`.finally` to handle the result. Create with `new Promise((resolve, reject) => {})`. Promises replaced callbacks for async flow because of once-only settlement, flat chaining, single error handling, and parallel utilities.
An object representing the eventual result of an async operation. It is a placeholder for a future value. A promise has three states: pending, fulfilled, and rejected. It settles (fulfills or rejects) exactly once.
Pending (initial, not yet settled), fulfilled (operation succeeded, has a value), and rejected (operation failed, has a reason/error). A promise transitions from pending to fulfilled or rejected once and cannot change state after settling.
Use new Promise((resolve, reject) => { ... }). The executor function runs immediately. Call resolve(value) to fulfill the promise, or reject(reason) to reject it. The executor usually starts an async operation.
Promises guarantee once-only settlement (no inversion of control), enable flat chaining with .then, use a single .catch for all errors, provide Promise.all for parallel operations, and enable async/await for synchronous-looking code.
.then runs when the promise fulfills. .catch runs when the promise rejects (or a .then throws). .finally runs when the promise settles (fulfilled or rejected), regardless of outcome. .finally does not receive the value or error.
Ready to master React completely?
Want to upskill yourself, crack your next interview, and get your dream job? Join our comprehensive course to dive deeper with high-quality video tutorials, solve interview questions, and a premium community.
Master React
Want to upskill yourself, crack your next interview, and get your dream job? Join our comprehensive course.

