JS: Promise.reject
Promise.reject(x)-
returns a promise in rejected state, with reject reason x.
Promise.reject(x)is effectivelynew 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.