Built-in built-in higher order functions that expect to receive a function as an argument
document.addEventListener('click', func);
function func() {
alert('You clicked me!');
}
Using anonymous function:
document.addEventListener('click', function() {
alert('You clicked me!');
});
Another built-in function
foreach
that receives a function as an argument
let greatColors = ['green', 'orange', 'yellow'];
greatColors.forEach(listColors);
function listColors(color) {
document.write('The color ' + color + ' is a great color<br>');
}