JavaScript Runtime Semantics
Objects & Property Descriptors
JavaScript objects are collections of properties. Each property has a descriptor that defines whether it is a data property or accessor, and whether it is writable, enumerable, and configurable.
- Objects are not just dictionaries
- Property lookup checks own properties first, then prototypes
- Descriptors control property behavior
- Enumerability affects iteration and serialization
- Freezing is shallow
| Field | Meaning | Applies to |
|---|---|---|
| value | Stored value | Data property |
| writable | Can value be changed? | Data property |
| get / set | Accessor functions | Accessor property |
| enumerable | Appears in enumeration? | Both |
| configurable | Can redefine/delete? | Both |
const user = {}
Object.defineProperty(user, "id", {
value: "u_123",
writable: false,
enumerable: true,
configurable: false,
})
console.log(Object.keys(user)) // ["id"]