JS: Property Descriptor

By Xah Lee. Date: . Last updated: .

What is Property Descriptor

Property Descriptor is the syntax for specifying Property Attributes . It has the form:

{ value: value, writable: boolean, enumerable: boolean, configurable: boolean }

Property Descriptor for Getter Property

{ get: function, enumerable: boolean, configurable: boolean }

Property Descriptor for Setter Property

{ set: function, enumerable: boolean, configurable: boolean }

Get Property Descriptor

Property Descriptor is used by several JavaScript functions to create or set properties together with attributes.

Set Property Descriptor

Default Values of Property Descriptor

value
undefined
configurable
false
enumerable
false
writable
false
set
undefined
get
undefined
// check default values of property attributes

const jj = Object.create(Object.prototype, { "p": { value: 1 } });
const xdesc = Reflect.getOwnPropertyDescriptor(jj, "p");

console.assert(xdesc.value === 1);
console.assert(xdesc.writable === false);
console.assert(xdesc.enumerable === false);
console.assert(xdesc.configurable === false);

JavaScript. Property

JavaScript. Define Properties and attributes.