FrontendDeveloper.in

JavaScript question detail

What is a higher order function

A higher-order function is a function that either accepts another function as an argument, returns a function as its result, or both. This concept is a core part of JavaScript's functional programming capabilities and is widely used for creating modular, reusable, and expressive code.

The syntactic structure of higher order function will be explained with an example as follows,

// First-order function (does not accept or return another function)
const firstOrderFunc = () =>
console.log("Hello, I am a first-order function");

// Higher-order function (accepts a function as an argument)
const higherOrder = (callback) => callback();

// Passing the first-order function to the higher-order function
higherOrder(firstOrderFunc);

In this example:

  1. firstOrderFunc is a regular (first-order) function.

  2. higherOrder is a higher-order function because it takes another function as an argument.

  3. firstOrderFunc is also called a callback function because it is passed to and executed by another function.

Back to all JavaScript questions
Get LinkedIn Premium at Rs 399