Why functions are considered First class function/Citizen? Read more..
Function can be assigned to a variable and pass it around. So a Function is treated as a value.
Why functions are considered Higher Order Function? Read more..
This behaviour rely on the function being a fist class citizen in the language.
- Function can be passed as a parameter.
- A Function can return another function.
Even a variable can be assigned to a function. Weird ..!
These types of function always Hoist with implementation current scope. So that function can be execute above the declaration.
These type of function do not have a name, so we call it anonymous function, but variable which holding that function will give name for it.
Arrow Function – Introduce in ES6
This was introduced with ES6 and very easy to access outer scope in this syntax.
Class Keyword — Introduce in ES6
This was introduced with ES6 and it is noting but syntactic sugar of regular function. How do you prove it’s a function? you can use typeof().
Function constructor– NOT RECOMMEND
You can use Function constructor to define a function. function body will be passed as second parameter in constructor. But this method is not recomend to use.