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

[ null, 1, null, 2 ]
      

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


Example 238. Null values in an object

{ "foo" : null }
      

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


Example 239. 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 240. 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 241. Empty sequence in an arithmetic operation.

() + 2
      

Result (run with Zorba): 


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

null + ()
      

Result (run with Zorba): 


Example 244. Empty sequence in a comparison.

() eq 2
      

Result (run with Zorba): 


Example 245. Null in a comparison.

null eq 2
      

Result (run with Zorba): false


Example 246. Null in a comparison.

null lt 2
      

Result (run with Zorba): true


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

null eq ()
      

Result (run with Zorba): 


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

null lt ()
      

Result (run with Zorba):