Member-only story
JavaScript Promises Demystified: Mastering Asynchronous Code with Ease
What is a Promise ?
The Promise object represents the eventual completion (or failure) of an asynchronous operation and its resulting value.
In other words,
A Promise is a special JavaScript object. It produces a value after an asynchronous operation completes successfully, or an error if it does not complete successfully.
The word ‘asynchronous’ means that something happens in the future, not right now.
Promise Constructor
let promise = new Promise(function(resolve, reject) {
// Code to execute
});The constructor function takes a function as an argument. This function is called the executor function.
The executor function takes two arguments, resolve and reject.
A promise object has the following internal properties:
state– This property can have the following values:
pending: Initially when the executor function starts the execution.fulfilled: When the promise is resolved.rejected: When the promise is rejected.









