David542
David542

Reputation: 110083

Practical differences between [] and null

For a numeric field, null can mean something very different than 0. For example, at a restaurant, someone's "Tip" could be $0, or it could be null, meaning that the bill was sent to the table but the patron has not signed the bill yet.

What would be some practical differences between [] and null? The only differences I can think of are at an integrity or storage level, but I'm having trouble thinking up real-world examples where data might have a different purpose using one vs. the other. What are some real-world examples for this difference?

Upvotes: 0

Views: 30

Answers (3)

Sandesh Herwade
Sandesh Herwade

Reputation: 21

If you consider an example of file & folder. An empty folder is [] and if it has some files then it like data inside an array. If there is no folder then it is NULL.

Also, have seen sometimes that user gets confused between ' ' (space) and null. Both are different. ' ' has (atleast) space in it and null means nothing.

Upvotes: 0

David Schwartz
David Schwartz

Reputation: 322

The use of null for arrays is useful to denote that the information is unknown, as opposed to there being no members of the array.

For example: In an application collecting information on real estate, one of the fields on a property might be an array of buildings. Null would mean that the person entering the information didn't specify the presence of lack of buildings (aka they don't know the information or don't want to say), while an empty array would mean that the property actually has no buildings (aka an empty lot).

This is particularly useful when collecting information from incomplete sources

Upvotes: 1

jamesfranco
jamesfranco

Reputation: 520

Think of a paper towel roll. A full paper towel roll is equivalent to some array with data inside. An empty paper towel roll with just the card board is []. No paper towel roll at all is null.

Upvotes: 0

Related Questions