JavaScript Functions can encapsulate modules that may be used multiple times in a program. Programs that can be called as event-driven results. Thus, a function is implemented to associate it with event-driven. This is different from other languages.
JavaScript Functions
Functions provide a convenient capability for program designers. During a complex program design, the program is always divided into relatively independent parts based on the functions to be completed, and a function is written for each part. Thus, each part is fully independent, with a single task, clear procedures, easy to understand, easy to read, and easy to maintain. JavaScript Functions can encapsulate modules that may be used multiple times in a program. Programs that can be called as event-driven results. Thus, a function is implemented to associate it with event-driven. This is different from other languages.
1. JavaScript function definition
Function name parameter, variable)
{
Function body ;.
Return expression;
}
Note: When a function is called, the variables or literal values can be transferred as variable elements. Function by the keyword Function
Definition. Function Name: define the name of your function. Parameter table, which is passed to the function for use or operation
Value. The value can be a constant, variable, or other expression. By specifying the function name) to call
Functions. Return must be used. The function name is case sensitive.
2. Form parameters in JavaScript Functions:
In the function definition, we can see that there is a parameter table after the function name. These parameter variables may be one or several. How can we determine the number of parameter variables? In JavaScript, arguments. Length can be used to check the number of parameters.
Example:
- Functionfunction_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);