Promise.reject()
Returns a promise that is rejected with the given reason.
Syntax
Promise.reject(reason)
Returns
Promise — A promise rejected with `reason`.
Examples
Promise.reject(new Error("nope"))
.catch(e => console.log(e.message));
Output
nope
Promise.reject("plain reason")
.catch(r => console.log(r));
Output
plain reason
Notes
- Unlike `Promise.resolve()`, the reason is not unwrapped even if it is
a promise.
- Prefer rejecting with an `Error` instance for useful stack traces.
Browser & runtime support
| Environment | Since version |
|---|---|
| chrome | 32 |
| firefox | 29 |
| safari | 8 |
| edge | 12 |
| node | 0.12 |