What is a callback in JavaScript? I typically read or hear people saying "add a callback to your function or piece of code" | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
+ 1

What is a callback in JavaScript? I typically read or hear people saying "add a callback to your function or piece of code"

Is callback function just similar to anonymous function? For example while registering onclick event, instead specifying what would happen on click in an altogether separate function, specify the function declaration and implementation directly in that very statement as part of callback. Are there any best practices on where to use callback and where not to use it?

15th Jul 2018, 4:54 AM
Abhishek Chaudhary
Abhishek Chaudhary - avatar
2 Antworten
15th Jul 2018, 5:27 AM
Sudarshan Rai
Sudarshan Rai - avatar
+ 1
function is normally called by program immediately for execution. Callback is a function that would be call by events that would be happened later, eg timer or external api data in functions, which all these functions would not be called immediately due to not times up or data delay.
15th Jul 2018, 6:30 AM
Calviղ
Calviղ - avatar