Sobes.tech
Junior

What is a promise and what are its states?

sobes.tech AI

Answer from AI

A Promise is an object representing the eventual completion (or failure) of an asynchronous operation and its resulting value.

A promise can be in one of three states:

  • Pending: The initial state, not yet fulfilled or rejected.
  • Fulfilled: The operation completed successfully. In this state, the promise has a resulting value.
  • Rejected: The operation failed with an error. In this state, the promise has a reason for rejection (an error).

Once a promise transitions to either Fulfilled or Rejected, it is considered settled. The state of a settled promise cannot change.