• source navigation  • diff markup  • identifier search  • freetext search  • 

Sources/ucode/tests/custom/00_syntax/24_null_coalesce

  1 Null coalescing operators return the right hand side of an expression of
  2 the left hand side is null.
  3 
  4 
  5 1. The `??` operator returns the right hand side of the expression if the
  6 left hand side evaluates to `null`.
  7 
  8 -- Expect stdout --
  9 is null
 10 false
 11 0
 12 -- End --
 13 
 14 -- Testcase --
 15 {%
 16         x = null;
 17         y = false;
 18         z = 0;
 19 
 20         print(x ?? "is null", "\n");
 21         print(y ?? "is null", "\n");
 22         print(z ?? "is null", "\n");
 23 %}
 24 -- End --
 25 
 26 
 27 2. The `??=` nullish assignment operator sets the left hand side variable
 28 or value to the right hand side expression if the existing value is null.
 29 
 30 -- Expect stdout --
 31 is null
 32 false
 33 0
 34 -- End --
 35 
 36 -- Testcase --
 37 {%
 38         x = null;
 39         y = false;
 40         z = 0;
 41 
 42         x ??= "is null";
 43         y ??= "is null";
 44         z ??= "is null";
 45 
 46         print(x, "\n");
 47         print(y, "\n");
 48         print(z, "\n");
 49 %}
 50 -- End --

This page was automatically generated by LXR 0.3.1.  •  OpenWrt