1

Here is a quote about Promise.then() from MDN.

Return value

Once a Promise is fulfilled or rejected, the respective handler function (onFulfilled or onRejected) will be called asynchronously (scheduled in the current thread loop). The behavior of the handler function follows a specific set of rules. If a handler function:

  • returns a value, the promise returned by then gets resolved with the returned value as its value.
  • doesn't return anything, the promise returned by then gets resolved with an undefined value.
  • throws an error, the promise returned by then gets rejected with the thrown error as its value.
  • returns an already fulfilled promise, the promise returned by then gets fulfilled with that promise's value as its value.
  • returns an already rejected promise, the promise returned by then gets rejected with that promise's value as its value.
  • returns another pending promise object, the resolution/rejection of the promise returned by then will be subsequent to the resolution/rejection of the promise returned by the handler. Also, the resolved value of the promise returned by then will be the same as the resolved value of the promise returned by the handler.

My question is why the state of promise returned by .then is "resolved" rather than "fulfilled" in second point?

It seems only have one state: fulfilled. Why not use the word "fulfilled" like the fourth point?

In first point and second point, both states of promise return by .then is "resolved".

About first point, in most cases, the state is "fulfilled". And if the callback return a thenable, the state of promise may be "rejected":

let thenableObj = {
    then(thenableRes, thenableRej) {
        thenableRej('thenable reject')
    }
}   

let p = Promise.resolve('foo')

p.then(() => {
    return thenableObj
}) // Promise{<rejecter>: 'thenable reject'}

So, I can accept the word "resolved". But, in the second point, I can't find any example to prove the word "resolved" is more precise than "fulfilled".

More specifically, can you give some examples to prove:

  1. the state of the promise returned by .then will be rejected when the callback in .then doesn't return anything.
  2. the state of promise returned by .then will be "locked in" to match the state of another promise when the callback in .then doesn't return anything.

if neither works, why don't we use the word "fulfilled" like fourth point than "resolved"?

VLAZ
  • 26,331
  • 9
  • 49
  • 67
youfu
  • 11
  • 2
  • 1
    resolved means no longer pending ... in other words, fullfilled or rejected is resolved - the language around then resolved/fullfilled has always been inconsistent – Bravo May 12 '22 at 05:20

0 Answers0