Message from JavaScript discussions

December 2018

— Why is this so much better ?, key)


Are you checking if the object has a property named X, or checking if the object has more than 0 properties?

— If it has a property named x

— I do:
if (object.key) {

— I don't have falsy properties anyway 😎

— Im reading trough airbnbs code style book, and they wrote that what i pasted

— Yeah, because that's the correct way

— Which is so good.. their explanation is:

— Why? These methods may be shadowed by properties on the object in question - consider { hasOwnProperty: false } - or, the object may be a null object (Object.create(null)).

Message permanent page

— Object.key -> returns undefined if key exists but is undefined, thus false

— Idon geddit

— Also true