Daily Software Tips & Tricks

Bite-sized knowledge to improve your coding skills daily.

Stop Using OR (||) for Default Values in JavaScript

May 23, 2026

When setting default values in JavaScript, it's common to see developers use the logical OR operator like this: 'const port = process.env.PORT || 3000'. While this works fine for falsy values like undefined or null, it can cause subtle bugs when your valid data is actually 0, false, or an empty string—all of which are also falsy and will get overridden by your default. Instead, reach for the nullish coalescing operator (??). It specifically checks only for null or undefined, allowing actual falsy values like 0 or false to pass through safely. Your configuration objects will thank you.