Callback Functions
A callback function is a function which is passed as an argument to another function.
e.g. function kind(){
console.log("I'm kind");
}
function rude(){
console.log("I'm rude");
}
function fun(a, b){
a();//calls kind()
b();//calls rude()
}
fun(kind, rude);
//Output:
I'm kind
I'm rude
Here, kind and rude are callback functions because they are passed as arguments to another function named as fun.
And fun is called a higher order function because it accepts functions (kind and rude) as parameters.
Top comments (2)
Thank you for the article it helps me a lot
Glad it helped 🙌
Thanks for reading the post!