What Are Higher-Order Functions in JavaScript?

A higher-order function either takes one or more functions as arguments, returns a function, or both.

Published November 20, 2026

A higher-order function is a function that takes another function as an argument, returns a function, or both. map, filter, reduce and addEventListener are everyday examples.

The concept

Functions are values in JavaScript, so you can pass and return them. This lets you abstract behaviour, not just data.

Typical uses: transforming collections, callbacks, decorators/wrappers and building configurable functions.

Pass behaviour in

[1, 2, 3].map(n => n * 2)
[2, 4, 6] // map is the higher-order function
[1, 2, 3, 4].filter(n => n % 2 === 0)
[2, 4]

Practical examples

Accepting a function

const total = [1, 2, 3].reduce((sum, n) => sum + n, 0)  // 6

Returning a function

const multiplier = (k) => (n) => n * k
const triple = multiplier(3)
triple(4) // 12

Wrapper that adds behaviour

const once = (fn) => { let done, r; return (...a) => done ? r : (done = true, r = fn(...a)) }
const init = once(() => console.log('init'))

Common mistakes

  • Mutating data inside map callbacks.
  • Chaining many passes over huge arrays.
  • Forgetting reduce needs an initial value.

Key takeaways

  • Functions that take or return functions.
  • Abstract behaviour, not only data.
  • Core to functional style in JS.

FAQ

Is a callback a higher-order function?

The function receiving the callback is higher-order.

First-class functions?

Languages where functions are values like any other.

More JavaScript articles