The deleteProperty(target, property) method

The deleteProperty trap is executed when we delete a property using either the delete operator or the Reflect.deleteProperty() method. It takes two parameters--that is, the target object and the property name.

This trap must return a Boolean, indicating whether the property was deleted successfully or not. Here is a code example that demonstrates how to use the deleteProperty trap:

const proxy = new Proxy({age: 12}, { deleteProperty(target, property) {     return delete target[property]; } }); Reflect.deleteProperty(proxy, "age"); console.log(proxy.age); //Output "undefined"

Get Learn ECMAScript - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.