In this video.
Let's talk about promise.
Well, promise is also another way of writing async code.
In the previous video, we use callback to write async code.
So in this particular video, let's see how we can also use promise to write a same code.
But before we continue on, let's have clear definition or clear meaning of a promise.
So in a layman's understanding of a promise, let's say that if you promise someone, there are three
things that comes out well.
So let's say that I promise you I'm going to create a course on ecommerce.
That is my promise.
So before promising, there are three states that goes into play.
One is about word thinking about the promise, and then after thinking it can happen that I can fulfill
my promise or three, I can fulfill my promise.
Well, let's take this in programming context.
Let's say that we want to watch YouTube videos.
So as soon as we enter the title of the video, we want to watch and hit enter.
Let's see what involve one.
We have what is called pending.
That is why you will see loading on your screen, meaning that your promise is now in pending state
and step two is as soon as we see the video that we are requesting, it means that your promise has
been fulfilled.
But let's say that due to some error, let's say network error, we see that we have Bush couldn't find
or network error or couldn't find.
In that case, your promise is what failed.
You could see in real life we have these three states and then in programming we have three states as
well.
So that's our whole promise is all about.
So technically a promise represents an object that may produce a value sometime in the future.
And the value is what we talk about in three states, right.
Pending for or success.
So let's move step by step.
Well, the values of the states can be one independent state, as we discussed.
And two is a camp for field or success.
And lastly, your promise can fail.
So that is the basic understanding of a promise.
So any time you make use of promise, it means that we are getting these three states that is coming
out when you make use of promise.
Well, so instead of using callback promises comes into play to make our life easier.
With promise, you're going to have clean code so that we can implement all these logic in our code.
Better still, for callback we can, but looking at syntax promise will be much easier to read than
callback.
So the next video.
Let's see how we can create our first promise.