const foo = '' ? 'truthy' : 'falsy'; // foo will be 'falsy' because an empty string is a truthy value
const bar = '' ?? 'default'; // bar will be '' because an empty string is not null or undefined
const baz = 0 ? 'truthy' : 'falsy'; // baz will be 'falsy' because 0 is a falsy value
const qux = 0 ?? 'default'; // qux will be 0 because 0 is not null or undefined
三元运算符和?? 两个问号的区别
最新推荐文章于 2023-07-05 16:47:28 发布