Skip to content
BENIBIX Learn

First-Class Function vs Higher-Order Function

With first-class functions, a function is a value you can store and pass. A higher-order function is one that takes in or hands back a function.

Development🧭 Programming Paradigms

First-Class Function

A function treated as a value. You can store it, pass it or return it.

A language has first-class functions when a function is treated like any other value. You can store one in a variable. You can pass one into another function, and a function can hand one back. JavaScript, Python and Kotlin all work this way. It is what makes callbacks and higher-order functions possible.

Example
A button takes a function to run when clicked. Lucy passes in her save function, and the button calls it later.
Why it matters
It lets you pass actions around like data. Sort rules, click handlers and retries all rely on it.
Full entry
Development🧭 Programming Paradigms

Higher-Order Function

A function that takes another function as input, or gives one back. map is one.

A higher-order function takes another function as input, or gives one back. map is the best-known one: you hand it a function and a list, and it runs that function on every item. sorted with a key, and filter, work the same way. They let you reuse the looping part and swap only the small action. Most modern languages have them built in.

Example
Emma passes str.upper to map with a list of two letters. Without writing a loop, she gets both letters in capitals.
Why it matters
They remove a lot of copy-pasted loops. One line says what to do to every item.
Full entry

In one line

First-Class Function
A function treated as a value. You can store it, pass it or return it.
Higher-Order Function
A function that takes another function as input, or gives one back. map is one.