3 ms·
I had this discussion recently in a pull request - the reviewer wanted to know why I was using both null and undefined. Like several people have mentioned, it’s
by steve_adams_86 6y ago
I had this discussion recently in a pull request - the reviewer wanted to know why I was using both null and undefined. Like several people have mentioned, it’s useful in JavaScript in particular to indicate known unknowns as null and unknown unknowns as undefined. Since it was a good question though I actually spent quite a bit of time and energy analyzing this and trying to figure out if my choice still made sense to me.
It’s somewhat reassuring to see these comments here because at the time, I couldn’t deny that my solution isn’t ideal. At the same time, I know that favouring a less explicit approach to describing empty values is inevitably even more confusing - there has to be some way to indicate why something is empty. It’s still hard to program with a solution you know isn’t ideal... I really wanted a better answer or to find a better way forward with the reviewer, but in JS land it seems like an unfortunate but viable way to work.