JavaScript and “First-class functions”.

js-minJavaScript is one of the languages which claim to feature “First Class Functions”. So, what does it mean to be 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.

Published by

Sunny R Gupta

During my career, I've led and built multiple projects from scratch. Over time I have helped migrate multiple portals from DC to Cloud making use of a decentralised architecture.