Archive by Author

First class functions in JavaScript: how comes functions are objects in JS (part 1)

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.

While this is understood by most JavaScript programmers, I believe the whole process of how this works is kinda obscure to most web developers and most of the time prefer to accept it as a statement of faith, so I’d briefly like to discuss how this works behind curtains, demonstrating and showing how (almost) everything in JS is an object.

In this first post, I’ll address one of the main reasons programmers do not fully grasp the fact that in JavaScript functions are objects too: its literal notation syntax.

Read More…