Settings

Theme

Always use undefined, and never null

writingjavascript.com

4 points by thatxliner 7 months ago · 3 comments

Reader

NoahZuniga 7 months 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.

thatxlinerOP 7 months ago

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

Keyboard Shortcuts

j
Next item
k
Previous item
o / Enter
Open selected item
?
Show this help
Esc
Close modal / clear selection