Objects and Property Keys
JavaScript objects are collections of properties. Property keys are strings or symbols. When a non-symbol key is used, JavaScript generally converts it to a string. Properties have more than just values: they can have descriptors such as writable, enumerable, and configurable.
This descriptor model explains behavior that ordinary object literal syntax hides.
Inspecting Property Descriptors
const user = {
name: 'Suriya'
};
console.log(Object.getOwnPropertyDescriptor(user, 'name'));💡 The descriptor reveals attributes such as writable, enumerable, and configurable in addition to the property's value.
Key Takeaways
- Object properties have descriptors.
- Property keys are strings or symbols.
- Object literals are convenient syntax over a richer property model.
Knowledge Check
Which of these can be an object property key?