1
00:00:00,200 --> 00:00:02,210
Here you can see side by side.

2
00:00:02,210 --> 00:00:08,570
I opened my Visual Studio Code editor and open my browser using Live server extension, and I already

3
00:00:08,570 --> 00:00:11,960
created a HTML file named index.html.

4
00:00:12,950 --> 00:00:15,290
First I'm going to create a script tag.

5
00:00:15,860 --> 00:00:19,130
Inside the script tag I'm going to create a normal function.

6
00:00:19,250 --> 00:00:21,440
Function test.

7
00:00:21,440 --> 00:00:23,900
And this function going to return a string.

8
00:00:24,470 --> 00:00:25,660
Hello world.

9
00:00:25,670 --> 00:00:27,560
Let's call the test function.

10
00:00:27,680 --> 00:00:34,700
And I want to call this function in my console console dot log inside the parentheses test.

11
00:00:35,460 --> 00:00:36,630
Let's save the file.

12
00:00:36,780 --> 00:00:38,970
You can see in my console it print.

13
00:00:39,000 --> 00:00:40,110
Hello world.

14
00:00:40,410 --> 00:00:42,180
There is nothing new here.

15
00:00:42,360 --> 00:00:44,520
It's a basically a normal function.

16
00:00:44,730 --> 00:00:48,120
Let's convert the function into a async function.

17
00:00:48,690 --> 00:00:54,270
For this we need to type async keyword before the function keyword.

18
00:00:54,360 --> 00:00:56,610
Now this is not a normal function.

19
00:00:57,150 --> 00:01:02,460
This function only works on asynchronous mode means in our background.

20
00:01:02,550 --> 00:01:07,020
And if I save this file, you can see in my console it returns a promise.

21
00:01:07,530 --> 00:01:08,790
You can see my console.

22
00:01:08,820 --> 00:01:09,330
Promise.

23
00:01:09,330 --> 00:01:09,960
Result.

24
00:01:09,990 --> 00:01:11,040
Hello, world.

25
00:01:11,190 --> 00:01:11,730
Promise.

26
00:01:11,730 --> 00:01:13,100
State fulfilled.

27
00:01:13,110 --> 00:01:14,640
So now it's clear for you.

28
00:01:14,640 --> 00:01:21,990
If we use async keyword before the function, it's return a promise and we already know we can use then

29
00:01:21,990 --> 00:01:23,880
or catch function with promise.

30
00:01:24,420 --> 00:01:25,260
Let's see.

31
00:01:25,970 --> 00:01:27,980
So I'm going to comment out this line.

32
00:01:27,980 --> 00:01:31,640
And then I'm going to call this function test.

33
00:01:32,210 --> 00:01:36,320
In our async function we don't need to use resolve or reject function.

34
00:01:36,320 --> 00:01:38,930
We can directly call then function.

35
00:01:38,930 --> 00:01:42,650
And inside the then function I'm going to create an arrow function.

36
00:01:43,440 --> 00:01:49,890
Whatever this function returns, and if it runs successfully, our then function call automatically

37
00:01:49,890 --> 00:01:57,900
and inside the then function we can print our return value console dot log inside the parenthesis result,

38
00:01:57,900 --> 00:02:03,090
and we need to create the result variable as parameter to store value result.

39
00:02:03,120 --> 00:02:08,910
You can take any name and if I save this file you can see in my console it print hello world.

40
00:02:09,270 --> 00:02:12,780
There is various method to create async function in JavaScript.

41
00:02:12,810 --> 00:02:16,560
We can create async function with normal error function.

42
00:02:16,740 --> 00:02:17,850
Let me show you.

43
00:02:18,060 --> 00:02:21,200
First I am going to take a variable named taste.

44
00:02:21,670 --> 00:02:26,540
Let taste equal to and this is our async function.

45
00:02:26,550 --> 00:02:29,430
So this is another way to create async function.

46
00:02:30,300 --> 00:02:34,350
If I save this file, you can see in my console it's written hello world.

47
00:02:34,680 --> 00:02:35,400
It's mean.

48
00:02:35,400 --> 00:02:36,630
It's worked properly.

49
00:02:36,870 --> 00:02:40,950
And if I want to fit in in an arrow function, yes I can.

50
00:02:41,670 --> 00:02:44,670
For this we do need to type function keyword.

51
00:02:45,030 --> 00:02:47,970
And then I use equal to and greater than sign.

52
00:02:48,120 --> 00:02:54,780
And you know if there is a single statement in our arrow function then we can delete this curly braces

53
00:02:54,780 --> 00:02:56,730
and we can make it one liner.

54
00:02:57,150 --> 00:02:59,850
And also we can remove this return keyword.

55
00:03:00,360 --> 00:03:03,360
And if I save this file you can see it's worked properly.

56
00:03:03,480 --> 00:03:07,230
So you can see how small our function has become.

57
00:03:07,380 --> 00:03:10,470
Let's try to understand what is await method.
