An Interest In:
Web News this Week
- April 27, 2024
- April 26, 2024
- April 25, 2024
- April 24, 2024
- April 23, 2024
- April 22, 2024
- April 21, 2024
April 10, 2022 09:16 am GMT
Original Link: https://dev.to/shamgurav96/-javascript-tip-delete-operator-1i5k
( 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:
Tweet
View Full Article
Dev To
An online community for sharing and discovering great ideas, having debates, and making friendsMore About this Source Visit Dev To