ai code academy · Explore coding

What is a promise in JavaScript?

A JavaScript promise represents the eventual outcome of an operation. It can be pending, fulfilled with a value, or rejected with a reason; having a promise does not mean the operation has already succeeded.

Discover ai code academyYour next step: guided practice and AI support in the app.

Download on the App Store ↗

Waiting for a result with an uncertain outcome

A parcel-tracking page may request a delivery update. While the result is pending, the page can still allow other interactions. The request might return tracking information or fail; a promise represents that outcome rather than the information alone.

A future result has several possible outcomes

A promise represents the eventual outcome of an operation. While a request is still pending, the information it will produce is not available yet. A successful result and a failed operation are different outcomes that the surrounding interface may need to represent.

The visible page can move on while an earlier request remains unfinished. A person might change a search term before the first result arrives. That makes the timing of a result part of its meaning, alongside the data it contains.

Explore how programs handle waiting

Asynchronous ideas help explain many connected features. Discover ai code academy as a companion for your coding journey and check its App Store listing for current information.

Source

Explore related topics