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