Knowledge Maxxing
← Back to topic library
Dev MaxxingBeginnerJavaScript75 sec

Promise

A Promise is a JavaScript object representing a value that isn't available yet but will eventually resolve successfully or fail with an error.

Prerequisite: JavaScript function

What matters

Promises give asynchronous operations, like network requests, a consistent way to handle eventual success or failure, instead of relying on deeply nested callback functions.

Example

A Promise returned by a network request eventually resolves with the response data, or rejects with an error if the request fails.

Common misconception

A Promise does not run its work synchronously in the background invisibly; it represents the eventual outcome, but the operation still runs asynchronously alongside other code.

Recall question

What two possible outcomes can a Promise eventually settle into?

Keywords and related concepts

Promiseasynchronousresolvereject

Related topics

async/await
Dev MaxxingBeginner
JavaScript function
Dev MaxxingBeginner