Where this matters
A count of zero can be meaningful. Choose a defaulting rule that preserves it when only missing values should be replaced.
console.log(0 ?? 10);
console.log(0 || 10);Read the full explanation
Nullish coalescing replaces only null and undefined. OR replaces every falsy left operand, including zero.
Trace the code
- The left value is zero in both expressions.
- The ?? operator checks only for null or undefined; zero passes through unchanged.
- The || operator tests truthiness, so it returns the right operand for zero. Neither operator always returns a boolean.
Why the other predictions differ
10 10— Zero is not nullish, so ?? preserves it.0 0— OR chooses ten because zero is falsy.
0 10
Reading this explanation does not record mastery. A correct submitted attempt can do so, including after review.
Change one thing
Replace zero with null. Both defaulting rules now select the fallback.
Predict the result, then run this self-contained snippet in your browser’s developer console. It uses only sample values and makes no network requests.
console.log(null ?? 10); console.log(null || 10);Check the variation’s output
10 10
Explain which binding, value, or operation changed before moving to the next challenge.