4. Type casting operation

nexl allows to perform a type casting directly in expression(s).
There are following 3 base data types you can use in nexl expressions:
:num
:bool
:str
Type casting operation applicable only for primitive data types and will be ignored for others.

Let's say we have a following string variable declared somewhere in a JavaScript file:
distanceToTheMoon = '384.400';
The following expression casts that string to a number:
${distanceToTheMoon:num}
If a primitive type cannot be casted to another primitive type the result will be undefined value:
${distanceToTheMoon:bool}

Let's say we have a colors JavaScript array:
colors = [ 'red', 'green' 'blue' ];
Type casting operation will be ignored if we try to cast that array to a primitive data type:
${colors:bool}

There are 2 additional operations to produce a null and undefined values in nexl expressions:
:null
:undefined ( or :u )
For example the following expression will be always evaluated to null value:
${distanceToTheMoon:null}

Watch a demo