Null
is kind of special. On the one hand, it's a plain 'ol symbol. You can use it the same way you could use any other symbol. And symbols are just expressions, so you can use Null wherever you can use an expression (it's not guaranteed to produce meaningful results, of course):
5 Null
Null[]
ConstantArray[Null, 5]
On the other hand, Null
is automatically inserted if the user has left a part of an expression empty where the syntax rules require an expression to be:
{,}
becomes {Null,Null}
a;
evaluates to Null
You might not see Null
explicitly in all of these cases, because the display form for a raw Null shows nothing.
Null has no semantics associated to it. Of course, you are free to adopt your own semantics for it in your own programs, but by default it's just an inert token that the system can use to make sure an expression is well-formed.
On the other hand, Missing
presumes some semantics. The system will generate a Missing
expression, for example, if you try to access an association with a missing key, or if you try to access an entity or property that is missing. You can supply an argument to Missing
to further clarify the semantics. For example Missing["Unknown"]
would be used differently than Missing["Nonexistent"]
. Several built in functions have rules for handling Missing
, typically by just ignoring it. There is also a nice helper function DeleteMissing
.