function provides a common and convenient ability for program designers. Usually in a complex program design, always according to the function to be completed, the program is divided into some relatively independent parts, each part of the writing a function. Thus, make each part fully independent, the task is single, the procedure is clear, understandable, easy to read, easy to maintain. JavaScript functions can encapsulate modules that may be used more than once in a program. And a program that can be invoked as an event-driven result. To implement a function to associate it with event-driven. This is not the same as other languages.
1. JavaScript function definition
Function name (parameter, variable)
{
function body;.
return expression;
}
Note: When calling a function, the variable or literal can be passed as a variable. Functions by keyword function
Defined. Function Name: Defines the name of its own functions. A parameter table that is passed to a function for use or operation.
Value, whose value can be a constant, variable, or other expression. By specifying a function name (argument) to invoke a
a function. The value must be returned using return. The function name is sensitive to case.
2, the function of the formal parameters:
In the definition of a function, we see the parameter table after the function name, which may be one or several. So how do you determine the number of parameter variables? Through arguments in JavaScript. Length can check the number of parameters. Cases:
Function function_Name(exp1,exp2,exp3,exp4)
Number =function _Name . arguments .length;
if (Number>1)
document.wrile(exp2);
if (Number>2)
document.write(exp3);
if(Number>3)
document.write(exp4);