Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

JavaScript · Class

Promise

Promise represents the eventual completion or failure of asynchronous work and its resulting value. It progresses from pending to fulfilled or rejected and supports handler-based chaining.

How it works

A Promise represents a value that may become available later or an operation that may fail. It starts pending and eventually becomes fulfilled or rejected; then(), catch(), and finally() attach work for those outcomes and return promises that enable chaining.

Syntax

new Promise(executor)

Parameters

NameTypeDescription
executorfunctionFunction executed by the constructor; it receives resolveFunc and rejectFunc.

Returns

A new Promise object.

Key points

  • Promise represents the eventual result or failure of asynchronous work.
  • The value need not be available when the Promise is created; the object stands in for that future value.
  • A newly created Promise is pending until its outcome is determined.
  • Fulfillment indicates successful completion and provides a fulfillment value.
  • Rejection represents failure and carries a rejection reason.
  • then() can receive separate callbacks for success and failure.
  • then(), catch(), and finally() attach follow-up behavior after a Promise settles.

Common mistakes

  • The Promise constructor must be invoked with new; calling Promise() as a regular function throws TypeError.
  • Exceptions thrown by the executor reject the newly created promise, so asynchronous setup should account for errors.
  • Calling resolve or reject settles the outcome only once; later attempts do not replace the first settlement.

Example: Chaining promise handlers

const delayed = new Promise((resolve, reject) => {
  setTimeout(() => resolve("done"), 10);
});

delayed
  .then((value) => `${value}!`)
  .catch((error) => `Failed: ${error}`)
  .finally(() => console.log("settled"))
  .then(console.log);

This promise resolves asynchronously, then the chained handlers transform the fulfillment value, handle rejection if needed, and run cleanup after settlement.

When to use it

Promisify callbacks

Wrap a callback-style API by invoking resolve on success and reject on failure.

Chain dependent work

Sequence asynchronous operations while passing each result to the next handler.

Handle errors and cleanup

Attach failure handling and cleanup to asynchronous operations.

Interview questions

QWhat states can a Promise have?

A Promise is an object representing the eventual success or failure of an asynchronous operation. It begins pending and transitions to fulfilled with a value or rejected with a reason; handlers registered with then() run for the corresponding outcome.

Follow-up: What does then() return? It returns another Promise immediately, allowing the result of one asynchronous step to feed the next step in a chain.

QHow does the Promise constructor work?

The constructor receives an executor function, which is called with resolve and reject functions. Calling resolve supplies the outcome, while calling reject reports failure; an exception thrown by the executor also rejects the promise.

Follow-up: What happens if resolve receives a thenable? The promise can remain pending while it adopts that thenable's eventual state.

QHow are promise handlers attached?

then() accepts up to two callbacks: one for fulfillment and one for rejection. catch() handles rejection, while finally() attaches cleanup that runs after the promise settles.

Follow-up: Why can these methods be chained? Each promise method produces or returns a promise, so later operations can consume the prior operation's result.

  • Promise()
  • Promise.all()
  • Promise.race()
  • Promise.allSettled()
  • Promise.any()
  • Promise.prototype.then()
  • Promise.prototype.catch()
  • Promise.prototype.finally()

Source: Promise - JavaScript | MDN. Checked 2026-10-15.