ai js promise return 2026-09-01
ai js promise return 2026-09-01
is it true, in a js promise object, the return value of resolve function or reject function has nothing to do with the promise state
(ai answer)
It depends on x. Calling resolve(x) (and never calling reject) only resolves the promise. That is not always the same as fulfilling it.
If x is not a thenable (not a Promise and not an object with a callable .then):
- The promise becomes fulfilled with
x. resolve(42)→ fulfilled with42resolve()→ fulfilled withundefined
If x is a thenable / Promise:
- The outer promise adopts
x’s eventual state. - It may stay pending until
xsettles. - It may become fulfilled with
x’s fulfillment value. - It may become rejected with
x’s rejection reason.
resolve(Promise.resolve(1)); // outer fulfills with 1 resolve(Promise.reject("err")); // outer rejects with "err" resolve(new Promise(() => {})); // outer stays pending forever
Rare extra cases where resolve(x) still rejects:
resolveis given the same promise it belongs to → reject withTypeError- Getting
x.thenthrows → reject with that error x.thenis not callable in a way the resolution procedure can use → usually fulfill withx, but a throwingthencan reject
So: reject never being called does not guarantee fulfilled. Only resolve(non-thenable) does. resolve(thenable) follows that thenable.