HTML and CSS Reference
In-Depth Information
Functional Programming
Understanding JavaScript begins with the realisation that it is a prototype-based object ori-
entated language. The next phase in understanding JavaScript comes from realising that it is
also a functional-orientated programming language.
There is no standard definition for what makes a programming language a “func-
tional programming language”. This section will highlight the aspects of
JavaScript that make it a functional programming language without addressing ar-
guments against considering it a functional language.
JavaScript has first class functions. This means variables can contain references to functions,
and functions can be passed as arguments to other functions.
The following is an example of assigning a function to a variable:
> f = function() {
console.log('Hello World');
The variable f now contains a reference to a function. If we execute:
> typeof f
The result will be
Strictly speaking this is incorrect: functions are objects, and have methods just like other ob-
jects. As we saw earlier, functions are not considered a distinct data type.
Following this precedence, you may expect that the typeof an array would be ar-
ray : it is not, it will return object .
Once you have a reference to a function, you can execute it by appending () to its name:
> f()
Hello World
Search WWH ::

Custom Search