The main difference between the Logical OR (||), and Nullish Coalescing Operator (??) is the that (??) returns its right-hand side operand when its left-hand side operand is only null or undefined and doesn't respect the other falsy value (e.g. 0, false, '').
The main difference between the Logical OR (
||
), and Nullish Coalescing Operator (??
) is the that (??
) returns its right-hand side operand when its left-hand side operand is only null or undefined and doesn't respect the other falsy value (e.g. 0, false, '').See the outputs:
For sure, the behaviour for
??
will be exactly the same as||
if z is undefiend or its value is null