js function parameter Arguments[0]

Source: Internet
Author: User

function box () {
return arguments[0] + ' | ' + arguments[1];

}
Alert (Box (1, 2, 3, 4, 5, 6));

Output: 1|2

Description: 1 ECMAScript function does not mind passing in the number of parameters, nor because the parameters are not uniform and error. As a matter of fact
The body of the function can receive the passed in parameters through the arguments object.

2 The Length property of the arguments object can be used to get the number of arguments.

Expand:

We can use the length of this property, to intelligently determine how many parameters, and then the parameters of the rational application.
For example, to implement an addition operation, all incoming numbers are added, and the number is indeterminate.
function box () {
var sum = 0;
if (Arguments.length = = 0) return sum;
If there are no parameters, exit
for (var i = 0;i < Arguments.length; i++) {
If you have one, accumulate it.
sum = sum + arguments[i];
}
return sum;
Returns the cumulative result
}
Alert (Box (5,9,12));

js function parameter Arguments[0]

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.