Hi freeCodeCamp forum users. I already know how to define and use a function. For example:
function sayHelloWorld() {
console.log("Hello World!");
}
sayHelloWorld();
But I don’t understand about a callback function, like this:
let myArray = ['apples', 'bananas'];
function printArray(arr) {
for (var element of arr) {
console.log(element);
}
}
myArray.forEach(printArray);
What does a callback function mean? And how it works?
Please answer.
Thanks!
Pummarin