function functions and parameter arguments of JavaScript

Source: Internet
Author: User
Tags function definition

JavaScript uses the function keyword to declare functions, you can return a value with return, or you can have no return value.

Recommendation: It is convenient to debug the code by either unifying the return value or not unifying the return value.

function definition Format:

function functionname (parameter) {//body}

When defining a function, the parameters can be written or not, JavaScript does not limit the number of arguments passed, nor does it mind the data type of the incoming parameter.

In the body of a function, you can access the parameter array through the arguments object to get each parameter passed to the function.

Arguments.length: Number of parameters

Each of its arguments is accessed with square brackets syntax. For example Arguments[0] is the first parameter passed in.

 function   Test () {Console.log ( "= = =    = = = "); Console.log ( ' agruments type: ' +

Operation Result:

The value of the arguments is always synchronized with the value of the corresponding named parameter, provided that the incoming parameter is consistent with the named parameter.

Example:

function Test (name,age) {    console.log (' age= ' + age)    arguments[1]=50;    Console.log (' to Agruments[1 ')}test (' line ', 20) after assigning a value of age= ' + age ';

Operation Result:

From the running results found that

The value of arguments[1] is synchronized with the value of age

Note: All parameters pass only values, and arguments cannot be passed by reference.


If the passed-in parameter is less than the named argument, the example below
function Test (name,age) {    console.log (' age= ' + age)    arguments[1]=50;    Console.log (' agruments[1 ' assigned to age= ' + age ')    console.log (' agruments[1 ') after assigning a value to arguments[1]= ' + Arguments[1])}test (' line ');
The results of the operation are as follows:

From the running results, we see:
If the passed-in parameter is less than the named argument, the named argument is not synchronized with the arguments

function functions and parameter arguments of JavaScript

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.