Functions of JavaScript

Source: Internet
Author: User
Tags expression function definition

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);

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.