Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
April 10, 2022 09:16 am GMT

( JavaScript Tip ) - delete Operator

delete operator is lesser-known operator in JavaScript. This operator is more specifically used to delete JavaScript object properties.

The delete operator removes a property from an object; if no more references to the same property are held, it is eventually released automatically.

const User = {  firstName: 'John',  lastName: 'Wick'};delete User.lastName;console.log(User);// Output: { firstName: "John" }console.log(User.lastName);// Output - undefined

If the property which you are trying to delete does not exist, delete will not have any effect and will return true.

If a property with the same name exists on the object's prototype chain, then, after deletion, the object will use the property from the prototype chain (in other words, delete only has an effect on own properties).

Note - delete operator doesnt delete property value rather the property itself.


Original Link: https://dev.to/shamgurav96/-javascript-tip-delete-operator-1i5k

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To