Functional object-oriented programming
JavaScript is a functional object-oriented programming language. However, it is quite different to other object-oriented programming languages such as C# or Java. Despite having a similar syntax, there are some important differences.
Functional programming in JavaScript
In JavaScript, functions are first-class objects. This means that functions can be treated like any other object: they can be created dynamically, assigned to variables, or passed into methods as arguments.
This makes it very easy to specify event callbacks, or to program in a more functional style using higher-order functions. Higher-order functions are functions that take other functions as arguments, and/or return another function. Here's a trivial example of filtering an array of numbers first in an imperative style and then in a functional style. Note that this example also shows JavaScript's array literal notation for creating arrays, using square brackets. It also demonstrates...