I've used some callbacks in JS, I want to know how JS implements the callback mechanism
. What is the principle
of callback in JavaScript?
Thx.
I've used some callbacks in JS, I want to know how JS implements the callback mechanism
. What is the principle
of callback in JavaScript?
Thx.
Functions are first class objects, thus they can be passed around like any other kind of object.
You pass a function as an argument to another function call, then you call it later.
Just because functions are first-class objects, we can pass a function as an argument in another function and later execute that passed-in function or even return it to be executed later. This is the essence of using callback functions in JavaScript