传参时,形参固定默认值
函数中改变此值
arguments还是调用时传的实参,跟形参默认值无关,跟函数里修改形参值无关
改变的对应参数值在函数中变成了修改的值,不是调用时传的实参,也跟形参默认值无关
函数中不改变此值
arguments得到的是实参数据而不是形参
传参时,形参不固定默认值
函数中改变此值
arguments值随着此值的改变而改变
改变的对应参数值在函数中变成了修改的值
函数中不改变此值
arguments得到的是实参数据而不是形参
如果形参在函数调用的时候赋值了,那就会和arguments属性中下标对应的数值相互影响否则不会
形参和实参是映射关系,但是如果用了默认值,那就是映射关系就不存在了,彼此不会影响彼此
arguments的length属性得到的是实参的个数
function(方法名).length是形参个数
function whatever(a, b, c = 5 ) {
// c=10;
Cs.log(arguments);
Cs.log(a,b,c);
//值的准确性校验
if (a === 1) {
console.log("The value of a is 1");
}
if (b === 1) {
console.log('The value of b is 2');
}
if (c === 3) {
console.log("The value of c is 3");
}
if (arguments.length === 5) {
console.log("We have passed in 5 paramters");
}
//验证传入的前三个实参与函数的3个形参匹配
if (arguments[0] === a) {
console.log('The first argument is assigned to a');
}
if (arguments[1] === b) {
console.log('The second argument is assigned to b');
}
if (arguments[2] === c) {
console.log('The third argument is assigned to c');
}
//验证额外的参数可以通过参数arguments获取
if (arguments[3] === 4) {
console.log("We can access the fourth argument");
}
if (arguments[4] === 5) {
console.log("We can access the fifth argument");
}
}
//调用函数时传入五个参数
whatever(1,2,3,4,5);