← All tutorials

GoCareerGo Tutorials

JavaScript Tutorial

Variables to closures, promises, the DOM and OOP — a complete JS reference.

Higher-Order Functions

A function that takes another function as an argument, returns a function, or both.

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