ObjectdefinePropertiesnewObj
Object.defineProperty is a method of the JavaScript Object constructor used to define a new property on an object or modify an existing one, returning the object itself. It offers fine-grained control over how a property behaves.
The method takes three arguments: the target object, a property name, and a descriptor object. The descriptor
If attributes are omitted, their defaults apply. For data properties, writable, enumerable, and configurable default to
Common uses include creating properties with controlled visibility (non-enumerable), implementing read-only properties, defining lazy or computed
Caveats include that redefining a non-configurable property with incompatible descriptors throws a TypeError. Object.defineProperty can be
Example: Object.defineProperty(obj, 'id', { value: 123, writable: false, enumerable: true, configurable: false }); This creates a non-writable, enumerable,