Cay Horstmann wrote:Now I always use undefined, except of course, when an API gives me null.
I do the same --
undefined seems to capture the spirit of a, well, undefined value better than
null; hair-splitting perhaps, philosophical perhaps, but a real distinction in my mind.
However, lots of code treats them interchangeably, and I cannot count the number of bugs I've had to deal with when code specifically checks for one or the other, but not both, in situations where a distinction is not made.
In
this topic, I pointed out the fairly new
nullish coalescing operator which helps a lot in this regard.