Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialcyber voyager
8,859 Pointsdelete() related question.
I used delete() on my object, it got "deleted" successfully but I could still console.log() the object that I removed from. I don't want to paste the code because It is allot and it will just make your life a bit harder, I (think)
let myList = new Set();
2 Answers
fgiorgosf
Courses Plus Student 21,260 PointsDid you try to delete an object property or an object ?
Can I please see the code fragment that deletes and the object declaration of what you are attempting to delete?
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/delete:
The delete operator removes a given property from an object. On successful deletion, it will return true, else false will be returned. However, it is important to consider the following scenarios:
- 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).
- Any property declared with var cannot be deleted from the global scope or from a function's scope. As such, delete cannot delete any functions in the global scope (whether this is part from a function definition or a function expression).
- Functions which are part of an object (apart from the global scope) can be deleted with delete.
- Any property declared with let or const cannot be deleted from the scope within which they were defined.
- Non-configurable properties cannot be removed. This includes properties of built-in objects like Math, Array, Object and properties that are created as non-configurable with methods like Object.defineProperty().