DEV Community

Discussion on: How do you deal with null vs undefined?

Collapse
 
willsmart profile image
willsmart • Edited

I just use undefined everywhere, and ruthlessly convert nulls to undefined as they come off an API.

I appreciate the difference. I'd sum it up as a nullable type being shorthand for a set with either zero or one item. null is just how we say the set has no entries, so null, in my head, has a type and is always used in the context of a nullable type. undefined never has a type, it's just a void.

But, I'm really not a fan of this kind of unneeded technical nuance. There are few cases IME where converting all the nulls to undefineds has broken my code, but having a source of undefineds sneak into a system I'd designed exclusively for nulls sounds like a day I'll never get back.

I get why someone would prefer to use null how it was designed, but I already make complex enough code, KISS has to be my mantra for this sort of thing.