filmov
tv
What is callback in JavaScript explained in 60seconds #javascript
![preview_player](https://i.ytimg.com/vi/k0nwEv68i3M/maxresdefault.jpg)
Показать описание
What is callback in #javascript ? here is a fun way to explain this concept in under 60 seconds.
Imagine that you're at a busy restaurant and you just ordered food.
The server tells you that your food will be ready soon, but in the meantime, you decide to pass the time by watching a movie on your phone. You started the movie, but you also want to make sure you know when your food is ready.
So you give your phone a special instruction: "When my food is ready, make a loud sound" You go back to movies.
In this scenario, the special instruction you gave your phone is like a callback function in JavaScript.
A callback function is a function that is passed as an argument to another function and is executed once that function completes its task.
It's like telling your phone to execute a specific task (making a loud beeping noise) once another task (your food being ready) is complete.
Just like the callback function in JavaScript, you don't have to constantly check for the completion of a task. You can tell the function to execute a specific task once it's done, and then move on to other tasks in the meantime.
This makes callbacks a powerful tool for creating efficient and organized code, just like your phone's ability to notify you when your food is ready.
Imagine that you're at a busy restaurant and you just ordered food.
The server tells you that your food will be ready soon, but in the meantime, you decide to pass the time by watching a movie on your phone. You started the movie, but you also want to make sure you know when your food is ready.
So you give your phone a special instruction: "When my food is ready, make a loud sound" You go back to movies.
In this scenario, the special instruction you gave your phone is like a callback function in JavaScript.
A callback function is a function that is passed as an argument to another function and is executed once that function completes its task.
It's like telling your phone to execute a specific task (making a loud beeping noise) once another task (your food being ready) is complete.
Just like the callback function in JavaScript, you don't have to constantly check for the completion of a task. You can tell the function to execute a specific task once it's done, and then move on to other tasks in the meantime.
This makes callbacks a powerful tool for creating efficient and organized code, just like your phone's ability to notify you when your food is ready.
Комментарии