📄 Table of Contents

◉ Brief Introduction to Promises

◉ Why to use Promises

1. Chaining & Order of Execution

2. Catch Mechanism

3. Remove CallBack Hell

◉ What is a Callback?

CallBack Hell

◉ 3 states of Promises

◉ Creating a Promise

Basic Promise Skeleton
const myPromise = new Promise();
const myPromise = new Promise((resolve, reject) => {  
// condition
});
let completed = true;
const myPromise = new Promise((resolve, reject) => {
if(completed) {
resolve('Promise is resolved successfully.');
} else {
reject('Promise is rejected');
}
});
let completed = true;
const myPromise = new Promise((resolve, reject) => {
setTimeout(() => {
if(completed) {
resolve('Promise is resolved successfully.');
} else {
reject('Promise is rejected');
}
}, 3000)
});

◉ Consuming a Promise: then, catch, finally

1) .then() method

2) .catch() method

3) .finally() method

◉ promise.race, any, all, allSettled

Promise.any

Promise.race()

Promise.all()

Promise.allSettled()

Chaining Promises in JavaScript :

◉ Switching from Traditional approach to Promises

◉ HTTP Interceptors

Summary

References:

Experience with Front-end Technologies and MERN / MEAN Stack. Working on all Major UI Frameworks like React, Angular.