Explain Higher Order Functions in JavaScript

 Functions that operate on other functions, either by taking them as arguments or by returning them, are called higher-order functions.


Higher order functions are a result of functions being first-class citizens in javascript.

Examples of higher order functions:

function higherOrder(fn) {
  fn();
}
     
higherOrder(function() { console.log("Hello world") }); 

function higherOrder2() {
  return function() {
    return "Do something";
  }
}
        
var x = higherOrder2();
x()   // Returns "Do something"

No comments:

Post a Comment

Here's a structured overview of key .NET interview topics with concise explanations

  1. .NET Fundamentals .NET Ecosystem : Unified platform (formerly .NET Core, .NET 5+) for web, mobile, desktop, cloud, and IoT. Cross-platf...

Best for you