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.