Programmer's Wiki

null (often NULL, or nil) is a constant used in many programming languages to indicate that the expected value is unknown. It is different from 0, the empty string, and false because these are known to be empty.

In some programming languages, myvar==null will always produce false (or an unpredictable result), because a non-value cannot be compared with a value. Some support the syntax "myvar is null", while others have special functions like isNull() and sometimes isNotNull().

Some languages differentiate null variables from undefined ones, while others initialize all variables as null.

In the lower languages (e.g. C, C++), NULL is not an ordinary value but a pointer (some languages implement this as a pointer with a value equal to zero); this is only true "under the hood" in others.

Some languages, such as Python (None) and Lua, implement null as a first-class value. In these languages, it is a specific and individual data type.


The following examples are in pseudocode.

myvar = null

if myvar is null {
    print "I'm sad because myvar is null"

if myvar is not null {
    print "I'm happy because myvar is NOT null"

See also[]

Null Object