A callback
is a function that is passed to another function as an argument. It is then executed after some operation has been completed. The following is an example of a simple callback function that logs to the console after some operations have been completed.
Source
https://coderbyte.com/algorithm/10-common-javascript-interview-questions
xxxxxxxxxx
12
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);
});
OUTPUT
:001 > Cmd/Ctrl-Enter to run, Cmd/Ctrl-/ to comment