Three switches on every property: writable, enumerable, configurable. What does defineProperty set for the switches left out, and what happens to a refused…
"Why won’t the value change?" and "why isn’t it in Object.keys or JSON?" are puzzling bugs until you know these switches. Much of the language uses them: class methods are not enumerable, Object.freeze turns writable and configurable off, and libraries use defineProperty for read-only or hidden properties.
defineProperty turns off the switches it is not told about; a literal turns them on
Object.keys / JSON.stringify Its default is enumerable: false, so it is not listed by keys, JSON, spread or for...in. Name enumerable: true when it should show.o.role = 'guest' changes nothing, and there is no error writable: false: in a plain script a refused write is dropped silently. In strict code (modules, 'use strict') it throws a TypeError, so the failure shows.delete o.role has no effect, the property is still there configurable: false rivets the property: delete gives false in a plain script and a TypeError in strict code. Its switches cannot change any more either, except writable from true to false. Check with getOwnPropertyDescriptor.'use strict' A TypeError: the failure shows.