In a situation where an object property is retrieved through a variable i.e.:
myObject[someField]
there is the possibility of someField
(which is a string) to be undefined
(the result of a potentially uninitialized string value). My experiments show that for all types of objects I can think of the result is undefined
i.e.:
anyObject[undefined] === undefined
Is this a well known behavior, something I can rely on? Can't seem to find something in related documentation and my alternative would be to re-write the above as
someField ? myObject[someField] : undefined;
but would really prefer the succinct way if there is a guarantee that undefined
is returned whenever we try to access the property undefined
.