Teacher, in the example you gave:
function func2(param1, param2) {
param1 = arguments[0] ? param1 : 600;
param2 = arguments[1] ? param1 : 300;
}
This ternary operator, if I call it like this: func(0, 0,);
I pass in If the parameter is 0, it will actually be judged as failure, and param1 and param2 will be assigned values of 600 and 300
猪老湿2021-06-21 09:49:27
It is inappropriate to set default parameter values in this way. In fact, js now supports default parameters, so there is no need for such trouble (es6)