9.7 Omitting descriptor properties
All properties of descriptors are optional. What happens when you omit a property depends on the operation.
9.7.1 Omitting descriptor properties when creating properties
When we create a new property via a descriptor, then omitting attributes means that their default values are used:
const car = {};
Object.defineProperty(
car, 'color', {
value: 'red',
});
assert.deepEqual(
Object.getOwnPropertyDescriptor(car, 'color'),
{
value: 'red',
writable: false,
enumerable: false,
configurable: false,
});
9.7.2 Omitting descriptor properties when changing properties
If instead, we change an existing property, then omitting descriptor properties means that the corresponding attributes are not touched:
const car = {
color: 'yellow',
};
assert.deepEqual(
Object.getOwnPropertyDescriptor(car, 'color'),
{
value: 'yellow',
writable: true,
enumerable: true,
configurable: true,
});
Object.defineProperty(
car, 'color', {
value: 'pink',
});
assert.deepEqual(
Object.getOwnPropertyDescriptor(car, 'color'),
{
value: 'pink',
writable: true,
enumerable: true,
configurable: true,
});