What is callback in JavaScript explained in 60seconds #javascript

preview_player
Показать описание
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.
Рекомендации по теме
Комментарии
Автор

thank you very much i just stuck and finding best explanation but i couldn't. after watching this video when i try to read articles its easy!! thank u very much !!!!😊

KEVALMEHTA-qeic
Автор

How is the phone is gonna notify me when im only using it to watch a movie ?

moetezbouazra
Автор

aa great example but i am still a little confuse anyone to help me?

ahmed_nadeem
Автор

She is just reading the text, not teaching. ..😂

akshaysaravanan
Автор

remove that bg music, its so irritating and distracting

Yashrajx
Автор

Disliked for not giving an actual code example

arielp