Object properties and attributes
Each object has a few properties. Each property, in turn, has a key and attributes. A property's state is stored in these attributes. All properties have the following attributes:
Enumerable (boolean): This indicates if you can enumerate the properties of the object. System properties are non-enumerable while user properties are enumerable. Unless there is a strong reason, this property should remain untouched.
Configurable(boolean): If this attribute is
false
, the property cannot be deleted or edited (it cannot change any of its attribute).
You can use the Object.getOwnPropertyDescriptor()
method to retrieve an object's own properties:
let obj = { age: 25 } console.log(Object.getOwnPropertyDescriptor(obj, 'age')); //{"value":25,"writable":true,"enumerable":true,"configurable":true}
Meanwhile, the property can be defined using the Object.defineProperty() method
:
let obj = { age: 25 ...