Above view on a flying passenger plane

What exactly are first-class functions?

JavaScript edition

Aphinya Dechalert
Published in
4 min readSep 7, 2020

--

In programming, a first-class function is when a function is treated as a variable. This is special because it means that a function can be passed into another function as an argument.

Not all languages support a first-class function idea, and these are usually natively imperative languages like C. Java and C++ also didn’t use to support first-class based ideas.

Imperative programming tells a computer how to do something — it’s a set of linear instructions that are executed in order. Declarative programming follows a generalized what should happen sequence. The control flow in a declarative language is not as strict and code can be executed asynchronously when required.

JavaScript is declarative by design and nature. The order of execution isn’t as vital towards arriving at the desired end-state for declarative programming.

Why is this important?

When it comes to first-class functions, you can assign a function to a variable but the actual value of the variable will not be set until it gets called. It’s a fuzzy area because the assignment does not happen instantly. Imperative programming requires clarity and first-class functions introduces a level of uncertainty.

--

--

Aphinya Dechalert
Modules&Methods

Where Development Meets Storytelling: Tech Writer, Editor & Dev Advocate. Translating Complexity into Clarity. DM me. linkedin.com/in/dechalert