1. function:
Function is a JS that is defined once but can be called multiple times. Code .
When a function is called by an object, this function is called the object method.
Function cssrain (x, y)
{
// Code
}
Explanation:
Cssrain: The function name;
(): Operator;
X, Y: the parameter;
2. function return value:
Function a (x ){
Document. Write (X );
}
Function B (y ){
Document. Write (y );
Return y;
}
Alert (A (1) // returns undefined because no return is written.
Alert (B (2 ))
3. Function statement and function quantity:
Function f (x) {return x * X ;}//
VaR F = function (x) {return x * X ;}//
The first is the function statement, and the second is to define an expression directly using the function. Of course, this method is used to create an anonymous function.
Although the direct quantity can be anonymous, you can also specify the function name;
For example:
VaR F = function fact (x) {return x * fact (x-1);} // the benefit of doing so; the call itself is very nice.
4. Function Name:
Function like_this (){}
Or function likethis () {}// camper
5. function parameters:
Because Javascript is a loose type language, you do not need to specify any data types for parameters. Parameters can be more or less,
For example: Function x (a, B) {}// we wrote two parameters.
If we pass three parameters, JS will automatically ignore multiple/
Instance:
Function x (a, B ){
Document. Write (a + "" + B );
}
X (1, 2, 3, 4 );
What happens if we pass only one parameter?
Function x (a, B ){
Document. Write (a + "" + B );
}
X (1 );
We found that undefined is output, so JS will assign less to undefined;
This may causeProgramError.
Solution:
Function x (a, B ){
VaR B = B | ""; // This is or operator. If the first B is undefined, that is, false, it will take the NULL Character
Document. Write (a + "" + B );
}
X (1 );