What reason is there to use null instead of undefined in JavaScript?

I don’t really have an answer, but according to Nicholas C. Zakas, page 30 of his book Professional JavaScript for Web Developers:

When defining a variable that is meant
to later hold an object, it is
advisable to initialize the variable
to null as opposed to anything else.
That way, you can explicitly check for the value null to determine if
the variable has been filled with an object reference at a later time

Leave a Comment