Do not set properties to null or empty, always use delete
.
Consider -
|
|
If you set any property to null -
|
|
You can expect similar results if you set the prop to null
.
If you really want to delete the object, do a delete
prop.
|
|
And before you ask - yes, this is covered when we were discussing (almost) everything about object and props in Javascript.
But, this deserves 30 lines of its own due to the sheer number of ‘doubts’ about how to delete a prop. Sheesh.. Haven’t y’ll heard of Google? No..? - you always have this post to link back to. You are welcome.
For all that there is - I still think an Object.removeProperty() would have done just fine instead of the confusing delete
. We have been brought up to not prefix delete
against commands without thinking five times - that is a lot of effort.