If I have some object that has a property that may or may not exist, is there a preferred way to check for its' existence?
// Good?
(someObj.property !== undefined && someObj.property !== null)
// Better?
(typeof someObj.property !== 'undefined')
// Best?
(someObj.property != null)
*The last != operator is on purpose:
Strict equality checks (
===) must be used in favor of abstract equality checks (==). The only exception is when checking forundefinedandnullby way ofnull. The use of== nullis also acceptable in cases where only one ofnullorundefinedmay be logically encountered, such as uninitialized variables.