map, filter and reduce are the most common built-in higher-order functions — each takes a callback function as an argument.
function withLogging(fn) {
return function (...args) {
console.log('calling with', args);
return fn(...args);
};
}
const loggedAdd = withLogging((a, b) => a + b);
loggedAdd(2, 3); // logs, then returns 5