Modern JavaScript
About Lesson

In this JavaScript lesson we are going to talk about JavaScript Promises, so Promises is a new feature in JavaScript ES6. and it is used for asynchronous programming in JavaScript. before Promises, async calls were handled by Callbacks. Promises resolved the Call Back Hell. a Promise is basically created when we are unsure  that the assigned task will be completed or not. the Promise object represents the completion (or failure) of an async operation and its resulting value. there are different stats for a promise.

 

Pending :  If an asynchronous function has not completed its task, the promise it returned will be in the pending  state.

Resolved : Whenever the asynchronous function completes successfully, it will set the promise into the resolved state.

Error: If an asynchronous function finishes with an error, then it sets the promise into the rejected stat, and there are two callbacks that are the part of promises in a chain.

then() function is used to receive and process the data.

catch() function is used to receive and process an error.