The Promise.reject(value) method

The reject() method of the Promise object takes a value and returns a rejected Promise object with the passed value as the reason. Unlike the Promise.resolve() method, the reject() method is used for debugging purposes and not for converting values into promises.

Here is an example that demonstrates how to use the reject() method:

const p1 = Promise.reject(4);p1.then(null, function(value){console.log(value);});Promise.reject({name: "Eden"}).then(null, function(value){console.log(value.name);});

The output is as follows:

4Eden

Get Learn ECMAScript - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.