js 语言 ?? 和 || 的区别
2023-08-20 本文已影响0人
markRao
const c = a || b
当 a 为 null、undefined、false、空字符串和数字0 时就会返回 b 的值
const c = a ?? b
当 a 为 null、undefined 时就会返回 b 的值
?? 是比 || 更严格更小细粒度的判空
const c = a || b
当 a 为 null、undefined、false、空字符串和数字0 时就会返回 b 的值
const c = a ?? b
当 a 为 null、undefined 时就会返回 b 的值
?? 是比 || 更严格更小细粒度的判空