Object.defineProperty will default to enumerable: false and configurable: false , while the getter syntax of the litter object will default to enumerable: true and configurable: true . This can be verified using Object.getOwnPropertyDescriptor(obj, "prop") .
This means that in the first case, prop will be displayed in for - in and Object.keys(obj) , and the delete obj.prop will fail (noisy in strict mode, silently otherwise). In the latter case, the opposite will be the case.
Note that Object.defineProperty (or Object.create or Object.defineProperties ) will allow you to individually select the configuration and enumeration of your properties, while the getter syntax of the object will not.
source share