Product SiteDocumentation Site

10.2. 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. Sequences cannot, as they represent the absence of any item.
Example 10.11. Null values in an array
[ null, 1, null, 2 ]
Result (run with Zorba):
[ null, 1, null, 2 ]

Example 10.12. Null values in an object
{ "foo" : null }
Result (run with Zorba):
{ "foo" : null }

Example 10.13. Null values in a sequence
(null, 1, null, 2)
Result (run with Zorba):
null 1 null 2

If an empty sequence is found as an object value, it is automatically converted to null.
Example 10.14. Automatic conversion to null.
{ "foo" : () }
Result (run with Zorba):
{ "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 10.15. Empty sequence in an arithmetic operation.
() + 2
Result (run with Zorba):

Example 10.16. Null in an arithmetic operation.
null + 2
Result (run with Zorba):
An error was raised: arithmetic operation not defined between types "js:null" and "xs:integer"

Example 10.17. Null and empty sequence in an arithmetic operation.
null + ()
Result (run with Zorba):

Example 10.18. Empty sequence in a comparison.
() eq 2
Result (run with Zorba):

Example 10.19. Null in a comparison.
null eq 2
Result (run with Zorba):
false

Example 10.20. Null in a comparison.
null lt 2
Result (run with Zorba):
true

Example 10.21. Null and the empty sequence in a comparison.
null eq ()
Result (run with Zorba):

Example 10.22. Null and the empty sequence in a comparison.
null lt ()
Result (run with Zorba):