JS Built-ins
Operatorsintermediate

Operators β€” ?? nullish coalescing

?? only falls back for null/undefined

Unlike ||, which falls back for any falsy value, ?? only falls back when the left side is null or undefined. This means 0, '', and false are not replaced.

Challenge: Write withDefault(val) that returns val ?? 'default'.

πŸ’‘ Hints (1)
  • β€’ ?? only triggers for null or undefined, not 0, false, or empty string