A writable property is a data property whose value can be changed by assignment. With Object.defineProperty, writable defaults to false, so make it true when the stored value should be assignable. section 9.1.2
Keep these descriptor rules in mind:
- Assigning to a non-writable property throws an error in strict mode. section 9.1.2
- A property that is writable but not configurable can change value, but its other property aspects cannot be changed. section 9.1.2
const obj = {};
Object.defineProperty(obj, "surfNinjaCount", {
value: 3,
});
console.assert(
obj.surfNinjaCount === 3,
"There are 3 surf ninjas.",
);
This data property has a value but omits writable, so it uses the default and is not assignable. section 9.1.2
