JS: Promise.reject

By Xah Lee. Date: . Last updated: .
Promise.reject(x)

returns a promise in rejected state, with reject reason x.

Promise.reject(x) is effectively new Promise((_, bb) => { bb(x); })

Example

const xfail = Promise.reject("gone bad.");
xfail.then(
 (x) => console.log("fulfilled with value:", x),
 (x) => console.log("rejected with value:", x),
);
// rejected with value: gone bad.