The composition of the function
function+ function name (parameter 1, parameter 2) {
function implementation;
}
The function name cannot be the beginning of a number, it can be a letter and an underscore;
function invocation: function name ();
Scope
Variables defined outside the function, called global variables, can be accessed throughout the document.
Variables defined inside a function are local variables and can only be accessed inside the function.
var a=10;
function aa () {
var a=20;
alert (a);
}
alert (a);
AA ()
A function is a data type that can be assigned to a variable
var f=function (b) {
return (B=B+1);
};
Alert (f (5));
Use f (parameter) when invoking
function can access functions inside itself
Function B () {
var a=5;
function bb () {
alert (a);
}
BB ();
}
b ();
Call function to use the return+ function when the intrinsic function has a return value
Function C () {
var a=10;
function bb () {
return a*2;
}
return BB ();
}
Alert (c ())
A function's call to its own intrinsic function
Function d (A, b) {
function DD (a) {
Return a+2
}
Return C=dd (a) +dd (b);
}
Alert (d (2,3))
function calls to other functions
function Add (A, b) {
return a+b;
}
function Sub (A, b) {
return a-B;
}
function bb (x,a,b) {
return x (A, b);
}
Alert (BB (sub,2,3))
Recursion of functions
function cc (a) {
if (a==1) {
return A;
}else{
Return A*CC (--A);
}
}
Alert (CC (4));
Use of function functions