A callback function is a function that is passed as an argument to another function and is called later when needed.
Here is a simple example:
function greet(name) {
console.log("Hello " + name);
}
function processUser(callback) {
callback("John");
}
processUser(greet);
Output:
Hello John
Here, greet is the callback function because we pass it to processUser().
The processUser() function then calls it using callback("John").
In simple words:
A callback is a function passed to another function to be executed later.
Top comments (0)