Sitemap
Vetriselvan Panneerselvam

Vetriselvan Panneerselvam

Frontend dev who clicks 'Inspect Element' for fun. Freelancing, experimenting, and oversharing my discoveries

Press enter or click to view image in full size
JavaScript Fallback Values Explained: OR (||) vs Nullish

Member-only story

JavaScript Fallback Values Explained: OR (||) vs Nullish (??)

2 min readNov 14, 2025

--

H
ey Devs đź‘‹

JavaScript has a funny way of confusing developers — mostly because it gives us so many ways to do the same thing.
I got bored of writing if conditions everywhere, so I jumped into using the OR operator (||) and the nullish coalescing operator (??).

Most of the time, I was using these operators without fully understanding their true purpose. (Not really — but it makes the story more dramatic, hehe. )

Not a Medium member? You can read the full article for free by clicking here đź”—

When I was a fresher, I saw these operators used everywhere. So let’s properly understand what they actually do.

1. Logical OR operator (||)

The logical OR operator returns the first truthy value, or the last value if nothing is truthy.

Falsy values in JavaScript include:

false, 0, "", null, undefined, NaN

Example

console.log("" || "default");     // "default"
console.log(0 || 42); // 42
console.log(null || "fallback"); // "fallback"

Because 0 and "" are falsy, || replaces them.

--

--

I'm Vetri, a full-stack developer and technical writer with 8+ years of experience. I share practical tutorials, real-world implementation patterns.

See more from me