Always use undefined, and never null

4 thatxliner 2 6/23/2025, 1:04:27 AM writingjavascript.com ↗

Comments (2)

NoahZuniga · 3h ago
I find the semantic distinction between null and undefined helpful. If something is undefined, my code hasn't set it. If it's null, the value has been set, but there is no data.

I've never experienced this, but if there is ever a point in my logic where undefined and null are both valid values, they probably require different handling, so just always using undefined is not a good idea.

thatxliner · 8h ago
There's also this article for further discussion: https://www.harness.io/blog/bias-against-null-javascript