...

/

Promises to the Rescue

Promises to the Rescue

Get introduced to the states and power of promises.

Newer asynchronous functions in JavaScript are designed to return a promise instead of taking a callback.

Definition: A promise is an object through which a function may propagate an error or result sometime in the future.

States

At any time, a promise is in one of three states:

  1. Pending
  2. Resolved
  3. Rejected

Pending

If an asynchronous function has not completed its task, the promise it returned will be in the pending state.

Resolved

Whenever the asynchronous function completes successfully, it will set the promise into the resolved state. At this time, the promise generates or emits the result passed through it; we refer to this as the promise resolves.

Rejected

If an asynchronous function finishes with an error, it sets the promise into ...

Access this course and 1400+ top-rated courses and projects.