Menu

Post image 1
Post image 2
1 / 2
0

Callback Functions in JavaScript Explained

DEV Community·Nikita Maharana·20 days ago
#PRwl2BkA
Reading 0:00
15s threshold

Nikita Maharana

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.

Read More