I want to know what the difference is between null
and undefined
in JavaScript.
Quote from "Eloquent Javascript" 3rd edition by Marijn Haverbeke:
The difference in meaning between
undefined
andnull
is an accident of Javascript's design, and it doesn't matter most of the time. In cases where you actually have to concern yourself with these values, I recommend treating them as mostly interchangeable
Honestly, at first, I am a bit skeptical about this advice. However, in my own interpretation, it is a lazy
(vs eager
) way to deal with their differences. Maybe, we don't have to deal with the differences at all. If we have to, we can delay our concern (util we have to) and not hyperactively/defensively
worry about it every step of the way as those values (null
and undefined
) flow through our code.
PS: This is not a direct answer to your question. This is just a related opinion.