I. Definition of functions
1. Functions are divided into named functions
function FuncName ()
Where FuncName ' is the name of the function and can be called by funcname (), you can use function to get its address.
2. Anonymous functions
var funcName = function () {}
The right side is the direct volume, and the left is the variable. The equivalent of assigning a direct amount to a variable. Can be called by funcname ().
Two. How to use
1. Direct use
function FuncName () {
Console info ();
}
FuncName ();
You can do it yong
FuncName ();
function FuncName () {
Console info ();
}
2. Assigning values to use
function FuncName () {
}
var temp = FuncName;
Temp ();
Three. Scope
1. General variable Scope
JS has no block-level scope, but has a function scope: A variable in a function that has meaning within the function to invoke
2. Reference scopes for functions
function can not be used outside, the outside cannot use the inside.
Four. Transfer of parameters
1. Parameter list
var num1 = 1,num2 = 2;
function FuncName (3,4) {
Console info (3);
Console info (4);
}
FuncName (num1,num2;)
2. Participate in the actual parameter
Outside of the function is the argument, which passes the formal parameter.
Five. Return value
Return can be used as a closing sentence for a function, as long as you encounter a return so that the nearest function stops and returns a value
The function is initially