A callback
the function is a function that is passed to another function as an argument and is executed after some operation has been completed. Below is an example of a simple callback function that logs to the console after some operations have been completed.
function modifyArray(arr, callback) {
// do something to arr here
arr.push(100);
// then execute the callback function that was passed
callback();
}
var arr = [1, 2, 3, 4, 5];
modifyArray(arr, function() {
console.log("array has been modified", arr);
});
In above example we have modifyArray function to which we have one passed one function as argument or parameter( “callback”), so once then function has executed we will call this callback function as normal function,
modifyArray(arr, function() {
console.log("array has been modified", arr);
});
Here, if we checked while calling the function we have passed the second paramter as anonymous function.