You need to know two things about promises :
The Promise object has 4 major properties:
Status or state:
Value: When the status of the promise is pending, then this property is undefined. The moment the promise is resolved, the value property is updated from undefined to the new value. So the value property acts like a placeholder till the time the promise finishes.
OnFulfillment: This is an array that contains functions that we attach to our promise object. We can attach some functions using the .then() method. When the value property is updated from undefined to the new value, JavaScript gives the chance to those attached functions one by one with the value property as their argument(if there is no piece of code in the call stack or global code).
Steps to create a promise : 1 - To create a promise, call the promise constructor. 2 - the promise constructor takes a callback as an argument. 3 - the callback function, which is passed inside the constructor function, accepts arguments such as resolve and reject. 4 - Inside the callback function, you can write your own logic. 5 - If you want to return something on success, then you can call the resolve function with data. 6 - error: call reject method with some error.