Q. Explain what a callback function is and provide a simple example

Telegram Join Our Telegram Channel

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);
});
Telegram Join Our Telegram Channel

Leave a Reply

Your email address will not be published. Required fields are marked *

Telegram Join Our Telegram Channel

Most Viewed

Monthly Best Selling Templates

Check the latest products added to the marketplace. Fresh designs with the finest HTML5 CSS3 coding.