Promises
In JavaScript, a promise is an object that wraps an asynchronous operation and notifies the program when the asynchronous operation completes. The promise object represents the eventual completion or failure of the wrapped operation. A promise is a proxy for a value not necessarily known. Instead of providing the value immediately, like a synchronous program, it promises to provide a value at some point in the future. Promises allow you to associate success and error handlers with an asynchronous action. These handlers are called at the completion or failure of the wrapped asynchronous process.
Promises States
Every promise has a state. A promise can only succeed with a value or fail with an error once. The state of a promise defines where the promise is in its work towards the resolution of a value.
A promise comes in three states: pending, fulfilled, or rejected. A promise starts in the pending state. This means that the async operation being done inside the promise is not complete...