JavaScript › Functional Programming

What is a higher-order function?

Beginner

Answer

A higher-order function either accepts one or more functions as arguments, returns a function, or both — array methods like map, filter, and reduce are common built-in examples.
function multiplyBy(factor) {
  return (n) => n * factor; // returns a function
}
const double = multiplyBy(2);
double(5); // 10
Real-world example Building a configurable validation function generator, like requireMinLength(5).

Common follow-ups: What's the difference between a higher-order function and a callback?