Article Directory
rest parameter
ES6 is newly added to compensate for this situation:
function sum(a,b){
console.log(a+b);
if(arguments.length>2)
for(var i=2;i<arguments.length;i++>)
console.log(arguments[i]);
}
I want to output additional incoming parameters. When using arguments, I must exclude the previously specified items
ES6 rest parameters can be changed like this:
function sum(a,b,...rest){
console.log(a+b);
console.log(rest);
}
The value of rest is an array composed of redundant items. The
output is: Array[the latter item]
rest can change the name at will
The true usage of return brackets
return
1;
js automatic semicolon is equivalent to
return;
1;
Add parentheses to meet the branch situation
return (
1
);
Pay attention to the semicolon