Instead of doing ...
if (typeof some !== 'undefined' && some.thing.variable === 'someValue')
... is it acceptable to just do the following?
if (some && some.thing.variable === 'someValue')
Instead of doing ...
if (typeof some !== 'undefined' && some.thing.variable === 'someValue')
... is it acceptable to just do the following?
if (some && some.thing.variable === 'someValue')
some
to avoid a ReferenceError
.Rationale: Since there are a few downvotes I think I need to give some context to why I think this is acceptable. I mention "private function" because in a private function the assumption is that we know which objects have which properties. So - regardless of style - the second write-up is an acceptable alternative to the original code snippet only if some
is indeed the object as advertised.
The function in question would need to have the variable declared and should not be accessible from outside. Some start these variables with an underscore:
// Declare variable
var _some;