Nullish Coalescing Zero
Predict Output Easy
Question
What does this code print?
Code
const val = 0;
console.log(val ?? "default");
Hint
?? only replaces null/undefined, not 0.
Explanation
val is 0, which is not null or undefined. So val ?? "default" returns 0. This differs from val || "default" which would return "default" (0 is falsy).
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.