This doesn't have anything to do with whether you're in a Node environment or not. If a specific attribute of the property is not set, they default to false
. Data properties have the following attributes (description in parentheses is for when the attribute is false):
configurable
(cannot be deleted, nor can attributes or type of property be changed)enumerable
(cannot be seen in a for-in loop)writable
(read-only but can still be deleted)value
(the value itself)
Because you haven't specified in your call to Object.defineProperty
that writable
is true
, it cannot be written to and therefore is read-only (reference).
By default, "standard" properties have all of these attributes (apart from value
) explicitly set as true
(internally), which is why it works normally. A good note by Mike Edwards is that attempting to do what you were doing in ES5 strict mode will throw a TypeError
.