1"Nullish Coalescing"
2
3If the left operand is null or undefined,
4the ?? expression evaluates to the right operand:
5
6null ?? "n/a"
7// "n/a"
8
9undefined ?? "n/a"
10// "n/a"
11
12Otherwise, the ?? expression evaluates to the left operand:
13
14false ?? true
15// false
16
170 ?? 100
18// 0
19
20"" ?? "n/a"
21// ""
22
23NaN ?? 0
24// NaN
25
26Notice that all left operands above are falsy values.
27If we had used the || operator instead of the ?? operator,
28all of these expressions would've evaluated to their
29respective right operands:
30
31false || true
32// true
33
340 || 100
35// 100
36
37"" || "n/a"
38// "n/a"
39
40NaN || 0
41// 0