JavaScript functions can be invoked with any number of arguments without specifying a few parameters when the function is defined. Because a function is weakly typed, there is no way to declare the type of argument it expects, and it is legal to pass any type of value to any function.
The 1.Js function can pass in different parameters, such as
function writenstring (STRMSG) {
document.write (strMsg + "<br>");
}
2.Js function return value, the JS function can return the results of the run, the function can be regarded as a black box, using the parameter input data to produce the desired results, such as
function one2n (intnumber) {
var inttotal = 0;
for (Var i=0;i<=intnumber;i++) {
inttotal +=i;}
return inttotal;
}
3.Js function's transfer value and address parameter
Pass value: Just pass the value of the variable into the function, the function will configure the memory to save the parameter value, so does not change the value of the original variable.
Pass: The memory location where the variable is actually saved is passed into the function, so if you change the value of the parameter in the function, the value of the original parameter is also changed.
Numbers, strings, and Boolean------values
objects, arrays, and functions----address
String Object--Address
An array of parameters for the 4.Js function
JS functions have a parameter array (Arguments array) object, called the Arguments object. When you call a function to pass in a parameter, the function can use the object of the parameter array to get the number of parameters and individual parameter values, even if the parameter names are not specified.
function Suminteger () {
var total = 0;
For (Var i=0. i<suminteger.arguments.length;i++) {Total
+ = Suminteger.arguments[i];
}
return total;
}
Call function
inntotal = Suminteger (100,45,567,234);
document.write ("function Suminteger (100,45,567,234):" +inttotal+ "<br>");
Variable range of 5.JS function
The JS function has two kinds of variables:
A variable declared within a function by a local variable, which can only be used within a program line within a function, and the program code outside the function cannot access the variable. \ Variables
Global Variables variables declared outside functions, the entire JS program's functions and program code can access this variable.