Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

The method for obtaining the value of a promise is to use the .then() method, which is available on all promise objects. The .then() method takes one or two arguments, the first argument is the function to be executed when the promise is fulfilled, and the second argument (optional) is the function to be executed when the promise is rejected. The function passed as the first argument to .then() will receive the resolved value of the promise as its argument.

Example:

const myPromise = new Promise((resolve, reject) => {
  resolve("Hello, world!");
});

myPromise.then((value) => {
  console.log(value); // Output: Hello, world!
});