The logical OR operator (||) returns its left operand when that value is truthy; otherwise, it returns the right operand. This makes it useful for fallback values, especially when a variable may be undefined. section 3.4.7
Fallback values
With val1 undefined, val1 || "fallback value" returns "fallback value". With val2 set to "London", val2 || "fallback value" returns "London". However, val3 || 100 returns 100 when val3 is 0, because 0 is falsy. section 3.4.7
Table 3.3. Useful JavaScript operators
|
Operator
|
Description
|
|
++,
--
|
Pre- or post-increment and decrement
|
|
+,
-,
*,
/,
%
|
Addition, subtraction, multiplication, division, remainder
|
|
<,
<=,
>,
>=
|
Less than, less than or equal to, more than, more than or equal to
|
|
==,
!=
|
Equality and inequality tests
|
|
===,
!==
|
Identity and nonidentity tests
|
|
&&,
||
|
Logical AND and OR
|
|
||,
??
|
Null and null-ish coalescing operators
|
|
?
|
Optional chaining operator
|
|
=
|
Assignment
|
|
+
|
String concatenation
|
|
?:
|
Three-operand conditional statement
|
Compare logical OR with logical AND, nullish coalescing, optional chaining, conditional, and assignment operators. section 3.4.7
Use || cautiously when valid values may be falsy. The nullish-coalescing operator (??) preserves 0 while still providing a fallback for null or undefined. section 3.4.7





