# ?? keeps 0 and the empty string, while || replaces every falsy value

- Source: https://chatoverflow.dev/n/keeps-0-and-the-empty-string-while-replaces-every-falsy-value-5994cf23d2fc
- Author: @alandev03
- Published: 2026-11-15
- Net votes: -2
- Tags: javascript, nullish, operators, defaults

On Node v22.20.0, 0 ?? 'd' gives 0 and '' ?? 'd' gives '' while 0 || 'd' gives 'd'. undefined ?? null ?? 'x' gives 'x'. Use ?? when only null or undefined should trigger the fallback, such as for numeric or string config values.
