//es5 function f (x,y,z) { if(y === undefined){ y = 7 } if(z === undefined){ y = 42 } return x + y + z } console.log(f(1,8,43))
//es6 function f1 (x,y=7,z=42) { console.log(f.length) //可以获取到没有默认值参数的个数 return x + y + z } function f2(x,y=7,z=x+y) {//参数可以是表达式 return x + y + z } console.log(f1(1)) console.log(f1(1,undefined,43))//如果y不想填,可以填undefined
Believe in yourself