July 2008
Beginner
356 pages
6h 8m
English
This is an important concept that we'll need later on—functions in JavaScript are actually data. This means that the following two ways to define a function are exactly the same:
function f(){return 1;}
var f = function(){return 1;}The second way of defining a function is known as function literal notation.
When you use the typeof operator on a variable that holds a function value, it returns the string "function".
>>> function f(){return 1;}
>>> typeof f"function"
So JavaScript functions are data, but a special kind of data with two important features:
As you saw before, the way to execute a function is by adding parentheses after its name. As the next example demonstrates, ...
Read now
Unlock full access