MENU
Promise.resolve() and Promise.reject()
The static function Promise.resolve(value) or Promise.reject(value) returns a promise that is resolved or rejected respectively, with the given value.
RESETRUNFULL
<!DOCTYPE html><html><body><script>
Promise.reject(100).then(
console.log,
n => {console.log(n*2)}); // 200
</script></body><html>
Passing a Promise object to Promise.resolve() is identical to calling the promise directly.
RESETRUNFULL
<!DOCTYPE html><html><body><script>
var p = new Promise(resolve=>{
resolve(100);});console.log(Promise.resolve(p) === p); // truePromise.resolve(p).then(
console.log,
n => {console.log(n*2)}); // 100
</script></body><html>
Passing to Promise.resolve() a thenable (an object with a 'method' taking two callbacks) is identical to calling a promise with the two callbacks in the thenable.
RESETRUNFULL
<!DOCTYPE html><html><body><script>
var thenable =
{then : (onFulfill, onReject) => {onFulfill('fulfilled');}};Promise.resolve(thenable).then(console.log);// fulfilledvar p = new Promise(resolve=>{resolve('fulfilled');}); //just identical to the abovep.then(console.log);// fulfilled
</script></body><html>