Understanding JavaScript Function As First-class Citizen
Sep 2, 2022 · 1 min readIntroduction
We often hear the phrase “Function is a first-class citizen in JavaScript”, but what exactly does it mean?
It means that JavaScript function possesses all the capabilities of JavaScript object and is thus treated like any other object in the language. And to be specific:
Function can be created with literals
Function can be assigned to variables, array entries, and properties of other objects
Function can be passed as an argument to another function
Function can be returned from another function
Function can be assigned properties
Wrap Up
Whatever we can do with object in JavaScript, we can also do with function. Function is the same as object, but with an additional, special capability of being invokable. That is, function can be called or invoked in order to perform an action.