In simple terms, inside a then
handler function:
A) When x
is a value (number, string, etc):
return x
is equivalent toreturn Promise.resolve(x)
throw x
is equivalent toreturn Promise.reject(x)
B) When x
is a Promise that is already settled (not pending anymore):
return x
is equivalent toreturn Promise.resolve(x)
, if the Promise was already resolved.return x
is equivalent toreturn Promise.reject(x)
, if the Promise was already rejected.
C) When x
is a Promise that is pending:
return x
will return a pending Promise, and it will be evaluated on the subsequentthen
.
Read more on this topic on the Promise.prototype.then() docs.