We are frequently using the following code pattern in our JavaScript code
if (typeof(some_variable) != \'undefined\' && some_variable != null)
{
Testing nullity (if (value == null)
) or non-nullity (if (value != null)
) is less verbose than testing the definition status of a variable.
Moreover, testing if (value)
(or if( obj.property)
) to ensure the existence of your variable (or object property) fails if it is defined with a boolean false
value. Caveat emptor :)