1. 参数默认值
- 默认是undefined
- 形参可以有默认值,形参、实参哪个有值取哪个ES6,默认值属于ES6的内容,打印出的是符合人性化的结果
- 形参有默认值,形参、实参无法统一、无论实参传入有值还是undefined(代码表现)
function test(a = 1, b) {
console.log(a, b)
console.log(arguments[0])
}
test(undefined, 1)
function test(a = 1, b) {
console.log(a, b)
console.log(arguments[0])
a = 8
console.log(a)
console.log(arguments[0])
}
test(undefined, 1)
function test(a, b) {
console.log(a, b)
console.log(arguments[0])
a = 8
console.log(a)
console.log(arguments[0])
}
test(2, 1)
function test(a, b) {
a = 3;
console.log(a)
console.log(arguments[0])
}
test(1, 2)
function test(a = undefined, b) {
console.log(a, b)
}
test(1, 1)
function test(a, b) {
a = arguments[0] || 1
console.log(a