Course contentsShow
← JavaScript
Lesson 435 of 2,72312. Higher-Order FunctionsFree lesson

The Higher-Order Function Concept

Defining higher-order functions as those that accept or return other functions, central to functional style.

The Higher-Order Function Concept

You'll learn what makes a function "higher-order" and why this pattern is central to modern JavaScript.

What Is a Higher-Order Function?

A higher-order function is simply a function that does at least one of these two things:

  1. Accepts another function as an argument, or
  2. Returns a function as its result

That's it! If a function treats other functions as inputs or outputs, it's "higher-order."

Why This Matters

You've already been using higher-order functions without realizing it. Every time you pass a callback or store a function in a variable, you're engaging with this concept. Higher-order functions are the foundation of functional programming style in JavaScript—they let you write flexible, reusable code by composing small functions together.

Examples You Already Know

// Example 1: Function accepts another function
function greet(name, formatter) {
  return formatter(name);
}

function shout(text) {
  return text.toUpperCase() + '!';
}

greet('alice', shout); // "ALICE!"
// greet is higher-order (accepts formatter function)
// Example 2: Function returns another function
function createMultiplier(factor) {
  return function(number) {
    return number * factor;
  };
}

const double = createMultiplier(2);
double(5); // 10
// createMultiplier is higher-order (returns a function)

Both patterns elevate functions from simple "doers" to flexible building blocks you can mix and match.

Key Takeaway: A higher-order function either accepts functions as arguments or returns functions as results—this simple pattern unlocks powerful composition and reusability in JavaScript.