Home > Web Front-end > JS Tutorial > body text

What are the key states and terms in JavaScript promises?

Mary-Kate Olsen
Release: 2024-11-05 12:42:02
Original
509 people have browsed it

What are the key states and terms in JavaScript promises?

The Intricate Terminology of JavaScript Promises

The world of JavaScript promises encompasses a myriad of terms that can leave developers perplexed. To navigate this maze, let us elucidate the precise meanings behind these key phrases.

Pending, Fulfilled, and Rejected

There exist three fundamental states for a promise:

  • Pending: The promise awaits determination, its outcome is still uncertain.
  • Fulfilled: The promise has successfully obtained a result value.
  • Rejected: The promise encounters a problem (usually an error), preventing it from delivering a result.

Settled vs. Resolved

The term settled encompasses both fulfilled and rejected states, indicating that the promise is no longer pending. Resolved, however, conveys that the promise has left the pending state, but it does not definitively signify whether it is fulfilled or rejected.

Resolve and Rejection

Resolve initiates the process of settling the promise's fate. This transition can result in three possibilities:

  • If the promise is resolved with a "plain" value, it is fulfilled.
  • If the promise is resolved with another promise (a thenable), it adopts that promise's state.
  • If the promise is resolved with a pending promise, it waits for that promise's resolution.

Deferring

Deferring entails providing an asynchronous promise for a result rather than delivering the result synchronously. Additionally, a deferred rejection is returned instead of raising a synchronous exception. Note that the term "defer" may also refer to the method name used in some libraries to create a Deferred object.

The above is the detailed content of What are the key states and terms in JavaScript promises?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template