I remember the advice: "Don't assign »undefined«
to something, only use it for testing (as in
»... === undefined«)."
But I forgot the reason.
Could it be that we do not want to write
..property = undefined
so that the /existing/ property with the value
»undefined« is not mistaken for a property that
does not exist? And we do not want to write
function() { ... return undefined; }
so that this function that returns something
which happens to be the value »undefined« is
not mistaken for a function that does not
return anything at all?
Or are there other reasons?
Which of the following three fragments should
be preferred, and why?
square_root(x) { if( x < 0 )return NaN; ... }
square_root(x) { if( x < 0 )return null; ... }
square_root(x) { if( x < 0 )return undefined; ... }
(actually, the word »undefined« best expresses the
mathematical way of wording, which says that the
square root of -1 is not defined [in the reals].)