promise

The promise object represents the completion or failure of an asynchronous operation and the value that results from this. We use promises when we will have a value that we do not yet know. This way you can associate handlers with an action that will occur.

A promise can have 1 of 3 states:

  • pending: This is the initial state and it has been neither fulfilled or rejected.
  • fulfilled: The operation was successfully completed.
  • rejected: The operation failed.

The eventual state of a pending promise can be either fulfilled with a value or rejected with an error. When either of these occur, the associated handler that is queued by a promise’s then method are called.