- New Parameter Functionality
Rest Params
function testParams( i , ...j){
var total = 0;
j.forEach( function(value, index) { total += value; });
return Math.pow(total,i);
}
testParams(2,1,2,3,4)
100
Rest Params with Arrow Functions
function testParams( i , ...j){
var total = 0;
j.forEach( value => total += value);
return Math.pow(total,i);
}
testParams(2,1,2,3,4)
100
default Params
function testDefault(i, power =2){
return Math.pow(i,power );
}
testDefault(10)
100
testDefault(10,3)
1000
No comments:
Post a Comment