Describes the parameters of javascript Functions.

Source: Internet
Author: User

Describes the parameters of javascript Functions.

Javascript functions can be called using any number of parameters, instead of specifying several parameters during function definition. Because a function is of a weak type, there is no way to declare the expected parameter type, and it is legal to pass any type of value to any function.

1. Js functions can input different parameters, such

function writeNString(strMsg){document.write(strMsg + "<br>");}

2. Js function return value. js function can return the running result. The function can be regarded as a black box. The required running result is generated after the parameter is input, as shown in figure

function one2N(intnumber){var intTotal = 0;for(var i=0;i<=intnumber;i++){ intTotal +=i;}return intTotal;}

3. Passing value and address parameters of Js Functions

Pass value: only pass the value of the variable into the function. The function will also configure the memory to save the parameter value, so it will not change the value of the original variable.

Address: Pass the actual memory location of the variable into the function. If you change the parameter value in the function, the original parameter value is also changed.

Number, string, and Boolean ---- pass value

Object, array, and function ---- Address Transfer

String object ------- Address Transfer

4. Js function parameter Array

All Js functions have an Array of parameters (Arguments Array) object called arguments objects. When a function is called to input parameters, the function can use the object of the parameter array to obtain the number of parameters and individual parameter values even if the parameter name is not specified.

Function sumInteger () {var total = 0; for (var I = 0; I <sumInteger. arguments. length; I ++) {total + = sumInteger. arguments [I];} return total;} // call the function inntotal = sumInteger (567,234, 45,); document. write ("function sumInteger (567,234,):" + inttotal + "<br> ");

5. JS function variable range

JS functions have two variables:

Local Variables are declared in the function. Variables can only be used in the program line of the function. Code outside the function cannot access this variable.

Global Variables are declared outside the function. The Variables can be accessed by functions and code of the JS program.

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.