JavaScript function definition and formal parameters

Source: Internet
Author: User

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:

 
 
  1. Functionfunction_Name(exp1,exp2,exp3,exp4)  
  2. Number=function_Name.arguments.length;  
  3. if(Number>1)  
  4. document.wrile(exp2);  
  5. if(Number>2)  
  6. document.write(exp3);  
  7. if(Number>3)  
  8. document.write(exp4); 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.