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:
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 } Object.defineProperty(obj, 'age', { configurable: false }) console.log(Object.getOwnPropertyDescriptor(obj, 'age')); //{"value":25,"writable":true,"enumerable":true,"configurable":false}
Though you would never use these methods, it is important to understand object properties and attributes. In the next section, we will discuss how some of the object
methods are used in context of some of these properties.
18.216.186.164