🔱 Higher Order Functions

What is a higer order function or HOF?

Which one is a function declaration?

Higher Order Functions

A higher order function is a function that takes a function as an argument, or returns a function. They are commonly used in functional programming, and are a powerful tool for abstracting away complexity.


// A function that takes a function as an argument
function add(x, y) {
  return x + y;
}
function subtract(x, y) {
  return x - y;
}
function math(x, y, operator) {
  return operator(x, y);
}

math(5, 2, add); // 7

Questions? Let's chat

Open Discord