1
00:00:01,600 --> 00:00:02,860
In this video.

2
00:00:02,890 --> 00:00:05,800
Let's talk about promise.

3
00:00:05,860 --> 00:00:11,860
Well, promise is also another way of writing async code.

4
00:00:12,130 --> 00:00:16,460
In the previous video, we use callback to write async code.

5
00:00:16,480 --> 00:00:23,820
So in this particular video, let's see how we can also use promise to write a same code.

6
00:00:23,830 --> 00:00:30,790
But before we continue on, let's have clear definition or clear meaning of a promise.

7
00:00:30,910 --> 00:00:38,260
So in a layman's understanding of a promise, let's say that if you promise someone, there are three

8
00:00:38,260 --> 00:00:40,990
things that comes out well.

9
00:00:40,990 --> 00:00:46,120
So let's say that I promise you I'm going to create a course on ecommerce.

10
00:00:46,120 --> 00:00:47,700
That is my promise.

11
00:00:47,710 --> 00:00:52,020
So before promising, there are three states that goes into play.

12
00:00:52,030 --> 00:01:02,440
One is about word thinking about the promise, and then after thinking it can happen that I can fulfill

13
00:01:02,470 --> 00:01:09,430
my promise or three, I can fulfill my promise.

14
00:01:09,640 --> 00:01:13,420
Well, let's take this in programming context.

15
00:01:13,510 --> 00:01:17,020
Let's say that we want to watch YouTube videos.

16
00:01:17,020 --> 00:01:22,600
So as soon as we enter the title of the video, we want to watch and hit enter.

17
00:01:22,600 --> 00:01:25,450
Let's see what involve one.

18
00:01:25,450 --> 00:01:27,910
We have what is called pending.

19
00:01:28,930 --> 00:01:34,750
That is why you will see loading on your screen, meaning that your promise is now in pending state

20
00:01:34,990 --> 00:01:42,190
and step two is as soon as we see the video that we are requesting, it means that your promise has

21
00:01:42,190 --> 00:01:43,000
been fulfilled.

22
00:01:43,480 --> 00:01:50,650
But let's say that due to some error, let's say network error, we see that we have Bush couldn't find

23
00:01:50,650 --> 00:01:52,630
or network error or couldn't find.

24
00:01:52,630 --> 00:01:56,140
In that case, your promise is what failed.

25
00:01:56,170 --> 00:02:03,340
You could see in real life we have these three states and then in programming we have three states as

26
00:02:03,340 --> 00:02:03,820
well.

27
00:02:03,820 --> 00:02:06,540
So that's our whole promise is all about.

28
00:02:06,550 --> 00:02:14,920
So technically a promise represents an object that may produce a value sometime in the future.

29
00:02:14,920 --> 00:02:19,690
And the value is what we talk about in three states, right.

30
00:02:19,690 --> 00:02:21,520
Pending for or success.

31
00:02:21,520 --> 00:02:24,430
So let's move step by step.

32
00:02:24,430 --> 00:02:30,940
Well, the values of the states can be one independent state, as we discussed.

33
00:02:30,940 --> 00:02:34,570
And two is a camp for field or success.

34
00:02:34,570 --> 00:02:37,600
And lastly, your promise can fail.

35
00:02:37,690 --> 00:02:42,160
So that is the basic understanding of a promise.

36
00:02:42,160 --> 00:02:47,920
So any time you make use of promise, it means that we are getting these three states that is coming

37
00:02:47,920 --> 00:02:50,320
out when you make use of promise.

38
00:02:50,770 --> 00:02:56,710
Well, so instead of using callback promises comes into play to make our life easier.

39
00:02:56,710 --> 00:03:03,100
With promise, you're going to have clean code so that we can implement all these logic in our code.

40
00:03:03,100 --> 00:03:10,180
Better still, for callback we can, but looking at syntax promise will be much easier to read than

41
00:03:10,180 --> 00:03:10,900
callback.

42
00:03:10,900 --> 00:03:12,520
So the next video.

43
00:03:12,520 --> 00:03:16,510
Let's see how we can create our first promise.

