qqwenwenti
qqwenwenti

Reputation: 63

Why is the result of the promise still `undefined` after execution?

Why is the result of the promise still undefined? Tutorial says it's gonna be error. Is it a Chrome display issue or anything I don't comprehend so far?

Upvotes: 1

Views: 70

Answers (1)

CertainPerformance
CertainPerformance

Reputation: 370619

You aren't returning anything from the error handler (alert returns undefined), so the Promise result tied to the error is undefined. If you return something from the error handler, you'll see it in the result.

new Promise((resolve, reject) => {
  setTimeout(() => {
    reject('err');
  }, 1000);
})

enter image description here

It's not a Chrome thing - this is how it'd work in any environment. (To access the error result, call .catch on the Promise and use the first argument)

Upvotes: 1

Related Questions