To see if the property payment
exists in the object payload
you can write
'payment' in payload
or if you want to know if the property is directly defined in the object (as opposed to being inherited through the prototype), say
payload.hasOwnProperty('payment')
The expression payload.payment
, when the value is 0, will produce false
when used as a boolean. This is because the following values will always act like false
:
0
false
NaN
undefined
null
- empty strings
The technical term for these values, that act as false
, is "falsy." So because 0 is falsy, whenever you write !payload.payment
, this value is actually true
for 0
and false
for everything else. Check for the missing property using one of the two techniques above (in
or hasOwnProperty
).