January 2017
Beginner to intermediate
550 pages
10h 6m
English
Functions in JavaScript are actually data. This is an important concept that we'll need later on. This means that you can create a function and assign it to a variable, as follows:
var f = function () {
return 1;
};
This way of defining a function is sometimes referred to as function literal notation.
The function () { return 1;} part is a function expression. A function expression can optionally have a name, in which case it becomes a named function expression (NFE). So, this is also allowed, although rarely seen in practice (and causes IE to mistakenly create two variables in the enclosing scope-f and myFunc):
var f = function myFunc() {
return 1;
};
As you can see, there's no difference between a named function expression ...
Read now
Unlock full access