Ans. A JavaScript callback is a function which is to be executed after another function has finished execution.
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 array here
arr.push(250);
// then execute the callback function that was passed
callback();
}
var arr = [1, 2, 3, 4, 5];
modifyArray(arr, function() { //calling function
console.log("array has been modified", arr);
});
2 Of 20 Js Interview Questions๐
Any comments or examples would be appreciated๐
Latest comments (0)