| In Object Oriented Context "null" is useful to indicate that some object doesn't have value for that property. What's interesting is, do we mean that in our data that attribute has no value? Or do we mean the real-world object represented by the data does not have that attribute? Does null mean a) We don't know the value of this attribute
for this object, or b) We do know that there is no value for this
attribute in the real-world object
represented by our data. In JavaScript because there is both null and undefined it is easy to assume that undefined means we don't know the value and null means we do know it has no value. EXAMPLE:
The attribute 'spouse'. Some people have a spouse some don't. So what does it mean if the value of the field 'spouse' is null? That we know there is no spouse, or that we don't know who the spouse is if any. In practical terms we can say null means "We don't know" which includes the case that there is no spouse. |
Javascript objects have two kinds of undefined that are both represented by the same value. You have to use another method to see which it is, and I've seen "foo" in this example used for the same thing as "null" in your example:
This is something you have to account for because the key is still there if you try to remove a value by just setting it to undefined: This is the right way to remove the key: