Daily Software Tips & Tricks
Bite-sized knowledge to improve your coding skills daily.
Use Nullish Coalescing for Safer Defaults
February 11, 2026
When setting default values in JavaScript, stop relying solely on the logical OR operator (||). If your variable is 0 or false, the OR operator will overwrite it with your default because those are falsy values. Instead, use the nullish coalescing operator (??). It only kicks in if the value is strictly null or undefined, preventing those annoying bugs where valid data gets wiped out by accident.