February 2019
Beginner
694 pages
18h 4m
English
The JavaScript language also has the concept of anonymous functions. These are functions that are defined on the fly and don't specify a function name. Consider the following JavaScript code:
var addVar = function(a,b) {
return a + b;
}
var addVarResult = addVar(2,3);
console.log("addVarResult:"" + addVarResult);
Here, we define a function that has no name and adds two values. Because the function does not have a name, it is known as an anonymous function. This anonymous function is then assigned to a variable named addVar. The addVar variable can then be invoked as a function with two parameters, and the return value will be the result of executing the anonymous function. The output of this code will be as follows:
Read now
Unlock full access