02.参数默认值(ES6)
小于 1 分钟
只有是undefined才会使用默认值
严格模式
function abc(a,b){
'use strict'
console.log(arguments)
console.log(a === arguments[0]) #true
console.log(b ===arguments[1]) #true
a = 'alpha'
b= 'best'
console.log(a === arguments[0]) #false
console.log(b ===arguments[1]) #false
}
abc()
计算形参的个数时,只会计算到形参之前的默认值的个数
默认值是一个函数,这个函数时反复调用的
参数默认值的暂时性死区(TDZ)
function getValue(value) {
return value + 1;
}
function abc(a = getValue(b), b) {
console.log(a, b)
}
abc(1, 2) // 1 2
abc(undefined, 2) // error