ES6解构赋值时,若赋undefined,是否有用
在学习过程中,做的一个有趣的尝试
ES6语法这样写
let [a,b = 'test'] = ['Mosan',undefined]
console.log(a)
console.log(b)
console.log(a+b)
结果打印出来是这样的
Mosan
test
Mosantest
即b没有被赋为undefined
查看转为的ES5语法是这样的
var a = 'Mosan',
_undefined = undefined,
b = _undefined === undefined ? 'test' : _undefined;
console.log(a);
console.log(b);
console.log(a + b);
如果赋为null,就有用