Nullish Coalescing
Question
What does nullish coalescing (??) do?
Hint
?? only checks null/undefined, not 0 or empty string.
Explanation
Nullish coalescing (??) returns the right operand if the left is null or undefined, otherwise the left. value ?? default provides a default value only for null/undefined. This differs from || which treats all falsy values (0, "", false, NaN) as triggering the default. Use ?? when 0 and "" are valid values: count ?? 1 keeps 0, while count || 1 replaces 0 with 1. ?? is a JavaScript feature (ES2020).
Related Resources
Related Lessons
- Nullish Coalescing
Learn nullish coalescing.
Look up unfamiliar terms
A beginner-friendly glossary explains jargon in plain English — variables, functions, DOM, Promise, and more.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.
Build real projects
Apply what you learned by building guided projects with starter code and solutions.