Predict Nullish Coalescing Output
Predict Output Easy
Question
What does this code print?
Code
console.log(null ?? "default");
console.log(undefined ?? "default");
console.log(0 ?? "default");
console.log("" ?? "default");
Hint
?? only falls back for null and undefined, not other falsy values.
Explanation
null ?? "default" returns "default" (null is nullish). undefined ?? "default" returns "default" (undefined is nullish). 0 ?? "default" returns 0 (0 is not nullish). "" ?? "default" returns "" (empty string is not nullish). Output: default, default, 0, and an empty line.
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.