JavaScript promise reject() Method Last Updated : 15 Dec, 2023 Comments Improve Suggest changes Like Article Like Report The Promise.reject() method is used to return a rejected Promise object with a given reason for rejection. It is used for debugging purposes and selective error-catching. The catch() method can be used for logging the output of the reject() method to the console that is catch() method acts as a career that carries the rejected message from the Promise.reject() method and displays that in the user's console. Syntax:Promise.reject(reason);Parameter: This method accepts a single parameter as mentioned above and described below: reason: It is the reason for which the promise is rejected.Return value: It returns the rejected promise with the given reason, either specified by the user or via the backend. Example 1: In this example, a Promise is instantly rejected with the reason "I am a reason of error." The catch() method logs the error to the console, showcasing a concise error-handling mechanism using JavaScript Promises. JavaScript // Initialize a promise variable and // use the reject() method with a // reason as a parameter let promise = Promise.reject("I am a reason of error"); // Catch the promise and pass the // function for logging the error in console promise.catch(function (error) { console.log(error); }); OutputI am a reason of error Example 2: In this example, a Promise in the main function simulates an error using a timeout and explicitly rejects it. The catch() method handles the rejection, logging "rejected the promise, something wrong happened" if an error occurs. This showcases asynchronous error handling with Promises in JavaScript. JavaScript function main() { return new Promise(function (resolve, reject) { setTimeout(() => { // This is the error which is handled // according to network requests const error = true; reject(); }, 2000); }); } main().catch(function () { // Only executed if rejects the promise console.log("rejected the promise, something wrong happened"); }); Output: rejected the promise, something wrong happenedExample 3: In this example, the main function creates a Promise where the condition checks if num is greater than 50. If true, the Promise is rejected. The catch() method handles the rejection, logging "Not greater than 100" to the console. This demonstrates a concise asynchronous error check using Promises in JavaScript. JavaScript function main() { return new Promise(function (resolve, reject) { num = 100; if (num > 50) { reject(); } }); } main().catch(function () { // Only executed if rejects the promise console.log("Not greater than 100"); }); OutputNot greater than 100 Supported Browsers:Google Chrome 32 and aboveEdge 12 and aboveFirefox 29 and aboveOpera 19 and aboveSafari 8 and above Comment More infoAdvertise with us Next Article JavaScript promise resolve() Method S shiv_ka_ansh Follow Improve Article Tags : JavaScript Web Technologies JavaScript-Methods Similar Reads JavaScript Promise constructor JavaScript Promises are used to handle asynchronous operations in JavaScript. They are easy to manage when dealing with multiple asynchronous operations where callbacks can create callback hell leading to unmanageable code. Promise constructor in JavaScript is mainly used to wrap functions that do n 2 min read JavaScript Promise constructor Property JavaScript Promise constructor property is used to return the Promise constructor function for the object. The function which is returned by this property is just a reference to this function, not a Promise containing the function's name. The JavaScript number constructor, string constructor, and bo 1 min read JavaScript Promise all() Method The Promise.all() method in JavaScript is used for handling multiple asynchronous operations simultaneously. It takes an array (or any iterable) of promises and returns a single promise that resolves when all the input promises resolve or reject if any one of the promises fails. This makes it ideal 6 min read JavaScript Promise allSettled() Method Promise.allSettled() method in JavaScript is used to handle multiple promises concurrently and return a single promise. This promise is fulfilled with an array of promise state descriptors, each describing the outcome of the corresponding promise in the input array. Unlike Promise.all(), Promise.all 2 min read JavaScript Promise race() Method The Promise.race() method returns a promise that fulfills or rejects as soon as one of the promises in an iterable fulfills or rejects, with the value or reason from that promise. We may think of this particular method as in the form of a real-life example where several people are running in a race 2 min read JavaScript promise reject() Method The Promise.reject() method is used to return a rejected Promise object with a given reason for rejection. It is used for debugging purposes and selective error-catching. The catch() method can be used for logging the output of the reject() method to the console that is catch() method acts as a care 3 min read JavaScript promise resolve() Method The Promise.resolve() method in JavaScript returns a Promise object that is resolved with a given value. If the value is a promise, it returns that promise; otherwise, it resolves the value as a new promise, making it useful for simplifying asynchronous code handling.What is Promise resolve() method 3 min read JavaScript Promise catch() Method JavaScript Promise catch() method is called whenever a promise is rejected. This method itself returns a promise so it can also be used to chain promises. This method is used for error handling. This method is mainly used after .then to chain a promise and handle reject condition. This method intern 2 min read JavaScript Promise then() Method JavaScript Promise then() method is called whenever a promise is resolved. It takes data from the resolved promise. It can take up to two arguments which are callback functions for the fulfilled and rejected cases respectively. Just like the catch() method it also returns a Promise so it is used to 2 min read JavaScript Promise finally() Method The finally() method of the Promise object is used to return a callback when a Promise is settled (either fulfilled or rejected).Syntax:task.finally(onFinally() { });Parameters: This method has a single parameter as mentioned above and described below:onFinally: It is the function that will be calle 1 min read Like