In this video, we will talk about callback.
So let's see what we will cover on the callback in this particular video.
First, we will explain callback with diagram and we will also talk about why do we need callback?
And in the next video we will see how we can use callback to write async code.
So let's get started.
Let's say that we want to watch videos from YouTube.
So definitely we need to talk to a server called YouTube server.
Great.
So the next step is that we make a request by the title of the video we want to watch, and then as
soon as we hit enter, it sent a request to this particular server.
Now, before getting back what we want.
It depends on a lot of factors.
So let's say that we are on a slow network.
It means it going to take some time before the response or the video you want to watch will be sent
to our browser.
So why is this one is loading or our request is loading?
We need an intermediate that hey please you don't worry.
When everything is ready, the server will now send the response to me.
Then I'll send back to you.
So let's say that in this context we are using this robot as our callback, meaning that the callback
is an intermediate between the actual function and what we want.
So the robot or the callback over here is going to wait.
So as soon as the server finished processing, then the callback would take the response or the actual
video, and then the robot or the callback would send the response also to the browser or to the user.
Now the user is now happy to watch the video.
So technically, what is callback?
Well, callback is a function that is passed to another function as an argument and this function is
then executed after the function that is passed to eight is executed, as we saw in the diagram.
Good.
So in the next video you will see how we can make use of callback to write async code.