📄 Table of Contents

Brief Introduction to Promises

Chaining

◉ 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) The .then() method

2) The catch() method

3) The finally() method

◉ promise.race, any, all, allSettled

Promise.any

Promise.race()

This is very similar to the Promise.any method, however, it has one key difference. While Promise.any will return only if one of the promises is Fulfilled, Promise.race will return if any of the promises are Settled.

Promise.all()

Promise.allSettled()

Summary

HTTP Interceptors

References:

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