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