We have some questions here that discuss delete in a more abstracted way, but I’m looking for practical examples of when use of delete could be used, versus doing something such as setting the property to null or undefined.
The delete operator deletes a property of an object.
What’s a case of a challenge faced somewhere, that delete was the best solution, versus something else?
Any property which has an empty setter (Because someone thought that was a good idea) needs to be deleted if you want to get rid of it.
The
inoperator returnstruefor any property that exist no matter it’s value. If you want it to returnfalseyou need todeletethe property.In both these cases setting it to
nullorundefineddoes nothing (Because it either has a setter that does nothing, or that’s how theinoperator works)