A null value, sometimes written as NULL, is where no value for a variable has been set, and/or it hasn’t been initialized. It is as if nothing exists for that variable. It’s lack of value can be found in both databases as well as programming languages.
We can see null being used in three different data types.
While numerically 0 (zero) shows there is no value to a number, we can still recognize that the value, or lack of value in this case, was set. With a null numeric value means that the value was never set and therefore it cannot be used. Most programming languages will default a numeric variable to zero, so you won’t have to test against a null value to save on potential run time errors.
The second time we see this, is with text. While text values can be blank, that still means the variable was set. Because of this, null is considered different than a blank value and most programming languages require that you check for both null and empty/blank because they server different purposes. Some will allow you to check if null or empty as a combination as well as individually, to make your life a little easier.
Being able to check this can be beneficial for programmers because they can check to see if a value has been set, even if it is blank, or they can check to see if no value had been set. For example, did a user enter a form field and leave it blank, or did they not get to that second of the form, and thus it is null.
Finally, you can check for null on objects. Since an object needs to be instantiated to be used, checking for a null value lets a programmer check to see if the object has been created, or if just a variable has been allocated for it. Not checking can lead to the dreaded null object exception found often in C# and Java code.
Other names for null
Different programming languages may represent null differently. For example, in JavaScript, the value undefined serves a similar purpose as a null value, and other languages us nil.
Definition: Null Value was originally found on Access 2 Learn
One Comment
Comments are closed.