Expression(expression)A phrase in JavaScript, JavaScript will calculate (evaluate) it to produce a result. A constant in a program is the simplest expression. Variable name is also a simple expression, and its value is the value assigned to the variable. Complex expressions are composed of simple expressions. For those who don’t know much about it, let’s take a look at the three function expressions in JavaScript!
The function name is a required part of the function declaration statement. Its purpose is like the name of a variable to which the newly defined function object will be assigned. For function definition expressions, this name is optional: if present, the name is stored only in the function body and refers to the function object itself.
Note:
Defining a function with an expression is only applicable when it is part of a large expression, such as defining a function during assignment and call.
1. Declarative functions
function area(width,height) { return width*height; } var size = area(3,4);
2. Expression function
var area = function(width,height) { return width*height; }; var size = area(3,4);
var area = (function() { var width = 3; var height = 5; return width*height; }());
Related recommendations:
#Another way to convert js function declarations into function expressions
The above is the detailed content of Three types of function expressions in JavaScript. For more information, please follow other related articles on the PHP Chinese website!