a callback is a function that is passed as an argument to another function, this makes functions more flexible
the callback is invoked inside the function
you can also use an anonymous function as a callback
the use of callbacks is very common, and are used often
———————————————————–
http://atechapart.com | http://linkedin.com/in/alvinsanchez
see my codepens @ http://codepen.io/_asanchez/
Original source
34 responses to “Javascript – How to Use Callbacks”
This is by far the best video online explaining callbacks. Thank you.
Thank u so much!
I m confused when to use parameter in function .Could make expliantion for me .Pls . 😀
A Tech Apart Thank you for the straight to the point explanation.
does it matter if you called the function "useCallback" below it or before it?
is it a good practice?
thanks
quick and to the point!
What is the difference if I write code like below?
useCallback(4);
function useCallback(x) {
document.write(x);
calbackX();
}
function callbackX() {
}
Great Vid thanks
David Schwimmer is a solid JS narrator! Many thanks, man.
use a Lav mic instead of a desktop (same surface as your keyboard) so it doesn't sound like your using a hammer on your keyboard?
excellent explanation!
Thanks, I'm starting to get it, I've encountered it before and was left stumped. Examples, I could follow. I had to stop and think about what was being done, and that combined with the output removed some of the fog swirling around this topic. Thanks again.
Perfect, muito obrigado!!!!!!!!!
Great video! Clear and concise! You should consider doing a series of tutorial videos 🙂
Jesus, I would hate to be your keyboard fam
Very cool. I'm starting to see the light.
THX 🙂
hangover? 😀
nice video – but why are you so angry with your keyboard?
your video s simply genious as all genius is simle)
I really enjoyed this video, a wonderful introduction to callbacks!
excellent. short simple and sweet
excellent. short simple and sweet
excellent. short simple and sweet.
excellent. short simple and sweet.
Quick and clear explanation. Thanks man.
I think I got it .
function person(name, gender, callback){
N = name.toUpperCase();
G = gender.toUpperCase();
callback(N,G);
}
function show_person(arg1, arg2){
console.log(arg1, arg2);
}
person("Ritchie", "male", show_person)
person("Max", "male", show_person)
Thanks for the video. Things start to get tricky when arguments are passed to the callback. I'm barely starting to understand this. I was wondering what you were gonna name the anonymous function then I was like oh yea duh lol.
Thank you!
I think you have the best examples for callback functions.
Thank you so much for explaining this.
most simplest explaination possible.
Helped me get a grasp of the basics. Thank you!
Most helpful 5 minutes of my life. Thank you.
waste of time