DEV Community

Anand gupta
Anand gupta

Posted on

Why functions in Javascript are called as First Class Objects?

Hey guys,

This is by far one of the most basic question that creates confusion amongst many javascript developers.

Here we go..

"A function is said to be the first class citizens or objects in javascript when they have all the capabilities that an object has."

  1. Functions can be assigned to variables and properties like any other
    object in javascript.

  2. Functions can be passed as an arguments into any other functions.

  3. An objects property can be a function (methods) or an array of
    functions.

  4. Functions can also be returned from another functions (closures).

In javascript, we can construct new functions during execution of a program, storing them in data structures, passing them as arguments to other functions and returning them as a value of other functions.

Thanks. :)

Top comments (0)