function:
Case-sensitive function strictly city; and repeating generated coverage. '
Function by function keyword definition , declare the function simply declare once, use many times.
Since calling a function:
Function expression can be used as "self-call."
Self-expression is invoked automatically be called (to start), and without the calling.
Function expressions will be automatically executed, if followed later in the expression ().
You can not call itself a function declaration.
You need to add parentheses around the function to indicate that it is a function expression;
function calc(num1,num2){
return num1+num2;
}
alert(calc());
alert(window.calc(3,5));
alert(calc(1,2,3,4,5,6));
num1, num2 characteristic parameter is: effect, long lifetime only once.
The following are the arguments alert.
Implement default parameters:
function calc1(num1,num2){
num1=num1||1;
num2=num2||2;
return num1+num2;
}
Output is 3.
Judge:
function calc4(x,y){
if(x===undefined){
x=0;
}
y=y===undefined?0:y;
return x+y;
}
Variable parameter function of the form:
Test function () {
var = paramsNum The arguments.length; // get the number of parameters passed
var SUM = 0;
for (var I = 0; I <paramsNum; I ++) {
SUM + = arguments [I];
}
SUM return;
}
Alert (Test (1,2,3,4,5,6));
Seeking maximum:
function test1(){
var paramsNum=arguments.length;
var max=0;
for(var i=0;i<=paramsNum-1;i++){
if(arguments[i]>max){
max=arguments[i];
}
}
return max;
}
alert(test1(123,3432,23456,445643));
Global variables: Scope for the entire program.
Local variables: the scope of the current function or cycle.