Codementor Events

What are “First-class functions” in JavaScript

Published Apr 21, 2017
What are “First-class functions” in JavaScript

JavaScript is one of the most popular languages which claims to feature “First Class Functions”. So, what does it mean to be a first class function? Let’s explore.

I like to compare it to being a first class citizen. Basically the right to freely move across boundaries in the country without being questioned of your purpose.

In the programming context, being first-class, gives JavaScript functions the ability to be saved in variables, passed around as arguments or even returned from other functions. Taking this a step further, functions can reside inside objects as one of the properties.

Note that in languages which support first-class functions, the name of the function does not play a big role. The name is just a variable pointing to the location of the function definition.

This might sound trivial to existing JS developers, but it is actually a boon. First-class functions are a necessity for “Functional Programming” paradigm.

Other languages which support them include PHP, Lua, Perl, Python, and IO.

This article originally appeared on my blog: ICodeStartups.

Discover and read more posts from Sunny R Gupta
get started
post commentsBe the first to share your opinion
Show more replies