A data property stores its value directly in a descriptor’s [[Value]] attribute: reading returns that stored value, and assignment replaces it when [[Writable]] permits. It contrasts with an accessor property, whose [[Get]] and [[Set]] functions compute or modify values. These descriptor pairs are mutually exclusive. section 5.2.1 section 5.2
The descriptor attributes explain behavior that otherwise looks like a runtime bug:
- [[Writable]] controls whether the stored value can change; a failed assignment silently does nothing in sloppy mode and throws in strict mode. section 5.2.3
- [[Enumerable]] controls visibility in for...in loops and Object.keys(), without preventing direct access. section 5.2.3
- [[Configurable]] controls deletion and later descriptor changes; it is distinct from [[Writable]]. section 5.2.3
- Object literals default these descriptor flags to true, whereas Object.defineProperty() defaults unspecified flags to false. section 5.2.3
A stored value that refuses assignment
const drawer = {}; Object.defineProperty(drawer, 'internalId', { value: 12345, writable: false, enumerable: false }); drawer.internalId = 54321; The property still reads as 12345 and does not appear in Object.keys(drawer). Object.getOwnPropertyDescriptor(drawer, 'internalId') exposes its value and controlling flags.
Table 5.1 The property descriptor attributes and the property types they apply to:
|
Name
|
Description
|
Data Properties
|
Accessor Properties
|
|
[[Value]]
|
A stored JavaScript value
|
✓
|
|
|
[[Writable]]
|
A boolean indicating whether [[Value]] can be changed
|
✓
|
|
|
[[Get]]
|
Code used to compute the property value
|
|
✓
|
|
[[Set]]
|
Code used to modify the property value
|
|
✓
|
|
[[Enumerable]]
|
A boolean indicating whether the property can appear in iterations
|
✓
|
✓
|
|
[[Configurable]]
|
A boolean indicating whether the property descriptor itself can be
changed or deleted
|
✓
|
✓
|
Compare the descriptor attributes that apply to data properties with those reserved for accessor properties. section 5.2
