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 207. Null values in an array

[ null, 1, null, 2 ]
      

Result (run with Zorba): [ null, 1, null, 2 ]


Example 208. Null values in an object

{ "foo" : null }
      

Result (run with Zorba): { "foo" : null }


Example 209. 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 210. 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 211. Empty sequence in an arithmetic operation.

() + 2
      

Result (run with Zorba): 


Example 212. 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 213. Null and empty sequence in an arithmetic operation.

null + ()
      

Result (run with Zorba): 


Example 214. Empty sequence in a comparison.

() eq 2
      

Result (run with Zorba): 


Example 215. Null in a comparison.

null eq 2
      

Result (run with Zorba): false


Example 216. Null in a comparison.

null lt 2
      

Result (run with Zorba): true


Example 217. Null and the empty sequence in a comparison.

null eq ()
      

Result (run with Zorba): 


Example 218. Null and the empty sequence in a comparison.

null lt ()
      

Result (run with Zorba):