Product SiteDocumentation Site

Chapter 18. Null vs. Empty Sequence

Null and the empty sequence are two different concepts.
Null is an item (an atomic value), and can be a member of an array or of a sequence, or the value associated with a key in an object. Empty sequences cannot, as they represent the absence of any item.
Example 18.1. Null values in an array
[ null, 1, null, 2 ]
Results:
[ null, 1, null, 2 ]

Example 18.2. Null values in an object
{ "foo" : null }
Results:
{
  "foo" : null
}

Example 18.3. Null values in a sequence
(null, 1, null, 2)
Results:
null
1
null
2

If an empty sequence is found as an object value, it is automatically converted to null.
Example 18.4. Automatic conversion to null.
{ "foo" : () }
Results:
{
  "foo" : null
}

In an arithmetic opration or a comparison, if an operand is an empty sequence, an empty sequence is returned. If an operand is a null, an error is raised except for equality and inequality.
Example 18.5. Empty sequence in an arithmetic operation.
() + 2
Results:

Example 18.6. Null in an arithmetic operation (failing).
null + 2
Error:
arithmetic operation not defined between types "js:null" an
d "xs:integer"

Example 18.7. Null and empty sequence in an arithmetic operation.
null + ()
Results:

Example 18.8. Empty sequence in a comparison.
() eq 2
Results:

Example 18.9. Null in a comparison.
null eq 2
Results:
false

Example 18.10. Null in a comparison.
null lt 2
Results:
true

Example 18.11. Null and the empty sequence in a comparison.
null eq ()
Results:

Example 18.12. Null and the empty sequence in a comparison.
null lt ()
Results: