January 2020
Intermediate to advanced
548 pages
13h 36m
English
The delete operator can be used to remove properties from objects, as such its only operand usually takes the form of a property accessor, like so:
delete object.property;delete object[property];
Only properties that are deemed configurable can be deleted in this manner. All properties added conventionally are, by default, configurable and can, therefore, be deleted:
const foo = { baz: 123; };foo.baz; // => 123delete foo.baz; // => truefoo.baz; // => undefined'baz' in foo; // => undefined
However, if the property has been added via defineProperty with configurable set to false, then it'll not be deletable:
const foo = {};Object.defineProperty(foo, 'baz', { value: 123, configurable: false});foo.baz; // => 123delete foo.baz; ...Read now
Unlock full access