Ask Your Question
4

What is the method for obtaining the value of a promise?

asked 2023-06-05 19:57:08 +0000

bukephalos gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2023-06-05 20:13:01 +0000

lakamha gravatar image

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!
});
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-06-05 19:57:08 +0000

Seen: 5 times

Last updated: Jun 05 '23