Nullish coalescing operator (??) - JavaScript | MDN
5
公开标注数
5
参与人数
2026-07-24 09:59:41
首次 Whisper
本页的公开 Whisper
划选高亮2026-07-24 13:20:41
原文高亮摘录
“the right-hand side expression is not evaluated if the left-hand side proves to be neither null nor undefined”
Whisper 随想笔记
Wait, does that mean it short-circuits like && and ||? I never noticed.
划选高亮2026-07-24 13:11:41
原文高亮摘录
“the right-hand side expression is not evaluated if the left-hand side proves to be neither null nor undefined”
Whisper 随想笔记
So it's basically lazy evaluation, that's useful for expensive calls.
划选高亮2026-07-24 10:17:41
原文高亮摘录
“The nullish coalescing operator avoids this pitfall by only returning the second operand when the first one evaluates to either null or undefined”
Whisper 随想笔记
This saved my life when 0 was a valid value in a form field, not gonna lie.
划选高亮2026-07-24 10:08:41
原文高亮摘录
“The nullish coalescing operator avoids this pitfall by only returning the second operand when the first one evaluates to either null or undefined”
Whisper 随想笔记
But honestly, who ever trips on 0 being falsy? Just use || like a normal person.
划选高亮2026-07-24 09:59:41
原文高亮摘录
“The nullish coalescing operator avoids this pitfall by only returning the second operand when the first one evaluates to either null or undefined”
Whisper 随想笔记
Finally, no more accidentally using 0 or empty string when I meant null.
分享本页 Whisper
短链接
https://domwhisper.com/s/5c31497d33fe嵌入代码
<iframe src="https://domwhisper.com/embed/5c31497d33fe" width="100%" height="480" style="border:0;border-radius:16px" loading="lazy"></iframe>