Dev Helpers

JavaScript / Modern objects

Keep false and zero with nullish defaults

Dev Helpers · July 30, 2026

A missing preference and a deliberately disabled preference need different defaults. Nullish coalescing keeps valid false and zero values.

Worked example

console.log([false, 0, null].map((value) => value ?? "missing"));

Result

[ false, 0, 'missing' ]

Implementation notes

An empty string may mean an intentionally blank label. If the UI wants a placeholder for both missing and blank text, express that separate rule explicitly.

Try it yourself

Compare null, undefined, an empty string and false.

Open the JavaScript example →

Editorial date July 30, 2026 · Published December 6, 2026

Related articles

Sum distances with a Euclidean norm

A diagonal is longer than either of its components. Math.hypot combines perpendicular distances without making the caller square each input.

Build an OS-independent path

Path conventions belong to the destination. Use an explicit path flavour when generating portable asset names.

Resolve ranked ties

A leaderboard needs an explicit tie policy. Ranking tied scores and sorting their display order are separate decisions.