Nullish Coalescing
noun
say it: “DUB-ul KWES-chun mark” /ˈdʌbəl ˈkwɛstʃən mɑːrk/ or “NULL-ish koh-uh-LESS-ing” /ˈnʌlɪʃ ˌkoʊəˈlɛsɪŋ/
The ?? operator in JavaScript: it gives the value on its left unless that value is null or undefined, and then gives the fallback on its right. A 0 or empty text stays.
What is Nullish Coalescing in JavaScript?
Nullish Coalescing — The ?? operator, which uses a fallback only when its left value is null or undefined.
const nickname = null;
const displayName = nickname ?? "Guest";
In a sentence
- “With nullish coalescing, pet.nickname ?? 'none yet' shows 'none yet' only when no nickname was given.”
Level: Apprentice · More JavaScript terms at this level
Updated