Interview Question

What is nullish coalescing operator?

?? supplies a fallback only for null or undefined.

💡 Concept ✅ Quick Revision ⚡ JavaScript

Answer

The nullish coalescing operator returns its right operand only when the left operand is null or undefined. • Values such as zero, false, and an empty string are preserved. • It differs from logical OR, which uses truthiness. • Parentheses are required when mixing it directly with && or ||.

Example

Code
const count = 0;
console.log(count ?? 10);
Output
0

Quick Revision

?? supplies a fallback only for null or undefined.