Nullish coalescing operator (??) - JavaScript | MDN
5
Public whispers
5
Contributors
2026-07-24 09:59:41
First whispered
Public whispers on this page
Text Highlight2026-07-24 13:20:41
Original Highlight Excerpt
"the right-hand side expression is not evaluated if the left-hand side proves to be neither null nor undefined"
Whisper Note
Wait, does that mean it short-circuits like && and ||? I never noticed.
Text Highlight2026-07-24 13:11:41
Original Highlight Excerpt
"the right-hand side expression is not evaluated if the left-hand side proves to be neither null nor undefined"
Whisper Note
So it's basically lazy evaluation, that's useful for expensive calls.
Text Highlight2026-07-24 10:17:41
Original Highlight Excerpt
"The nullish coalescing operator avoids this pitfall by only returning the second operand when the first one evaluates to either null or undefined"
Whisper Note
This saved my life when 0 was a valid value in a form field, not gonna lie.
Text Highlight2026-07-24 10:08:41
Original Highlight Excerpt
"The nullish coalescing operator avoids this pitfall by only returning the second operand when the first one evaluates to either null or undefined"
Whisper Note
But honestly, who ever trips on 0 being falsy? Just use || like a normal person.
Text Highlight2026-07-24 09:59:41
Original Highlight Excerpt
"The nullish coalescing operator avoids this pitfall by only returning the second operand when the first one evaluates to either null or undefined"
Whisper Note
Finally, no more accidentally using 0 or empty string when I meant null.
Share this page's whispers
Short link
https://domwhisper.com/s/5c31497d33feEmbed snippet
<iframe src="https://domwhisper.com/embed/5c31497d33fe" width="100%" height="480" style="border:0;border-radius:16px" loading="lazy"></iframe>See what people are discussing on developer.mozilla.org
Install DomWhisper to view live whispers as you browse, and join the discussion.
Get the extension