Explain the term 'First-class functions' in relation to Javascript

488 views Asked by At

Can someone explain this term for me and describe a typical programming situation where first-class functions are used? Thanks

1

There are 1 answers

0
Libin C Jacob On BEST ANSWER

We often hear that JavaScript functions are first-class functions, meaning both functions and objects are treated by the language as the same thing. In practical terms, a function can be stored as a variable, inside an array or an object, as well as it can be passed as an argument or be returned by another function. That makes functions “first-class citizens” in JavaScript.

These are the examples:

var myfunc2 = function(a)
{
 return a + 1;
};

var myfunc2 = function myfunc4(a)
{
 return a + 1;
};

Refer the following links

http://odiseo.net/javascript/first-class-functions-in-javascript-how-comes-functions-are-treated-as-objects-in-js

http://www.developerfusion.com/article/84433/first-class-functions/