Function declarations
Function declaration code calls the function to create the future. Function can be called before the position statement. Sample code is as follows:
-
// can be called before the position statement
-
var size=area(3,6);
-
function area(width,height){
-
return width*height;
-
};
-
// can be called in position after the statement
-
var size2=area(2,4);
Function expression
The expression of the function to be present in a location, which is referred to as function expression. In the function expression often used anonymous functions. The following code sample
Area function = var (width, height) {
return width * height;
};
// can only be invoked after the function expression is defined
var size = area (2,4);
immediately invoke function expression (IIFE)No name, execute one time when the interpreter through them. Sample code is as follows:
var area=(function(){
var width=6;
var height=8;
return width*height;
}());