Open In App

Where is rejected property stored for a Promise in JavaScript ?

Last Updated : 04 Mar, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

Rejected property for a Promise in JavaScript is Stored under the promise’s internal object’s property named PromiseState, the rejected property of the promise is stored, and later when we have implemented catch in order to make our promise fulfilled then that PromiseState property’s value becomes Fulfilled.

Now lets see this with an example,

Since JavaScript doesn’t provide any special explicit property or Public API (Application Programming Interface) through which we could externally identify that particular thing, so we may check the rejected property of the promise inside the internal promise’s object itself.

Example: In this example, we will simply create a promise that will use the reject() method which then shows the rejected state of a promise along with a certain message passed inside the reject() method, and all of this we will see in browser’s console’s output itself where we will visualize this with pictorial representation.

Javascript




let new_promise = new Promise((resolve, reject) => {
    reject("Rejected Promise...!!");
});
 
new_promise
    .then((result) => {
        console.log(result);
    })
    .catch((error) => {
        console.log(error);
    });


Output:


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads