1
00:00:00,820 --> 00:00:05,010
In this video, we will talk about callback.

2
00:00:05,200 --> 00:00:11,290
So let's see what we will cover on the callback in this particular video.

3
00:00:11,620 --> 00:00:21,970
First, we will explain callback with diagram and we will also talk about why do we need callback?

4
00:00:22,180 --> 00:00:29,660
And in the next video we will see how we can use callback to write async code.

5
00:00:29,680 --> 00:00:31,810
So let's get started.

6
00:00:37,040 --> 00:00:41,360
Let's say that we want to watch videos from YouTube.

7
00:00:41,540 --> 00:00:46,790
So definitely we need to talk to a server called YouTube server.

8
00:00:47,060 --> 00:00:47,760
Great.

9
00:00:47,780 --> 00:00:54,500
So the next step is that we make a request by the title of the video we want to watch, and then as

10
00:00:54,500 --> 00:01:00,980
soon as we hit enter, it sent a request to this particular server.

11
00:01:01,520 --> 00:01:04,500
Now, before getting back what we want.

12
00:01:04,519 --> 00:01:06,680
It depends on a lot of factors.

13
00:01:06,680 --> 00:01:10,250
So let's say that we are on a slow network.

14
00:01:10,520 --> 00:01:17,210
It means it going to take some time before the response or the video you want to watch will be sent

15
00:01:17,210 --> 00:01:18,530
to our browser.

16
00:01:19,270 --> 00:01:23,520
So why is this one is loading or our request is loading?

17
00:01:23,530 --> 00:01:28,150
We need an intermediate that hey please you don't worry.

18
00:01:28,150 --> 00:01:32,740
When everything is ready, the server will now send the response to me.

19
00:01:32,740 --> 00:01:34,150
Then I'll send back to you.

20
00:01:34,360 --> 00:01:41,590
So let's say that in this context we are using this robot as our callback, meaning that the callback

21
00:01:41,590 --> 00:01:47,560
is an intermediate between the actual function and what we want.

22
00:01:48,190 --> 00:01:52,090
So the robot or the callback over here is going to wait.

23
00:01:52,980 --> 00:01:59,250
So as soon as the server finished processing, then the callback would take the response or the actual

24
00:01:59,250 --> 00:02:07,080
video, and then the robot or the callback would send the response also to the browser or to the user.

25
00:02:07,110 --> 00:02:11,190
Now the user is now happy to watch the video.

26
00:02:13,110 --> 00:02:16,470
So technically, what is callback?

27
00:02:16,500 --> 00:02:25,110
Well, callback is a function that is passed to another function as an argument and this function is

28
00:02:25,110 --> 00:02:32,610
then executed after the function that is passed to eight is executed, as we saw in the diagram.

29
00:02:34,520 --> 00:02:35,030
Good.

30
00:02:35,060 --> 00:02:42,260
So in the next video you will see how we can make use of callback to write async code.

