空值合并运算符(??)

空值合并运算符
空值合并操作符(??)是一个逻辑操作符,当左侧的操作数为 null 或者 undefined 时,返回其右侧操作数,否则返回左侧操作数。

let str=null??"开门"
//“开门”

let foo=undefined??"开门"
//"开门"
let string="0"??"大吉"
//“0”

猜你喜欢

转载自blog.csdn.net/weixin_47389477/article/details/117998904