ES2020 ?? 运算符
ES2020新增了判断null与undefined的运算符
类似于||
|| 判断运算符 可用于判断null、undefined、false、0
const bool = false;
console.log(bool || 'default value');
// 'default value'
const bool = 0;
console.log(bool || 'default value');
// 'default value'
const bool = null;
console.log(bool || 'default value');
// 'default value'
const bool = undefined;
console.log(bool || 'default value');
// 'default value'
?? 判断运算符 仅判断null以及undefined
const bool = null;
console.log(bool ?? 'default value');
// 'default value'
const bool = undefined;
console.log(bool ?? 'default value');
// 'default value'
const bool = false;
console.log(bool ?? 'default value');
// false
const bool = 0;
console.log(bool ?? 'default value');
// 0