Promise.reject
Returns a Promise object that is rejected with a given reason
Syntax
Promise.reject(reason)Parameters
| Parameter | Type | Description |
|---|---|---|
| reason | any | The reason this Promise is rejected |
Return Value
A Promise that is rejected with the given reason
Examples
const p = Promise.reject(new Error('fail'));
p.catch(err => console.log(err.message)); // 'fail'function validateAge(age: number): Promise<number> {
if (age < 0 || age > 150) {
return Promise.reject(new Error('Invalid age'));
}
return Promise.resolve(age);
}Promise.reject('error')
.catch(reason => console.log(reason)); // 'error'Understanding Promise.reject
The Promise.reject method in JavaScript returns a Promise object that is rejected with a given reason. It belongs to the Promise object and is one of the most widely used methods for working with promise values in modern JavaScript and TypeScript applications.
The method signature is Promise.reject(reason). It accepts 1 parameter: reason. When called, it returns a promise that is rejected with the given reason. Understanding when and how to use reject() helps you write more expressive, readable code.
Common use cases for Promise.reject include data transformation, input validation, API response processing, and building reusable utility functions. It works well alongside related methods like promise-resolve, promise-catch, promise-then, enabling you to chain operations together for complex data manipulation pipelines.
Browser support for Promise.reject is excellent across all modern browsers including Chrome, Firefox, Safari, and Edge. It is also fully supported in Node.js and Deno. For older environments, transpilation with Babel or a polyfill may be needed.
Browser Compatibility
Supported in all modern browsers (Chrome, Firefox, Safari, Edge) and Node.js. Part of the ECMAScript standard.
Related Methods
Promise.resolveReturns a Promise object that is resolved with a given value
Promise.prototype.catchAttaches a rejection handler callback to the promise and returns a new Promise resolving to the return value of the callback if called, or the original fulfilled value if the promise is resolved
Promise.prototype.thenAttaches callbacks for the resolution and/or rejection of the Promise, and returns a new Promise
More Promise Methods
Other methods in the Promise object
Related Tools
More Promise Methods
Explore JavaScript Methods
Browse our complete reference of 410 JavaScript methods with syntax, examples, and explanations.