var foo = new Object(); foo.fieldUndefined = undefined;
Here are the results from running on a browser console.
As we can see, both fieldUndefined and fieldNotExist properties show undefined value but fieldUndefined does actually exist.
Some people have suggested to use typeof to check for the type. If it returns undefined, then the field doesn’t exist.
However, this doesn’t work either.
The only way to test an object property actually existed is via Object.hasOwnProperty.
Just make sure no one up your object’s prototype chain has overridden the method which is bad practice. Alternatively, uses Object.prototype.hasOwnProperty.call instead.