Last Updated : 03 Jun, 2024
The logical OR (||) (logical disjunction) operator for a set of operands is true if and only if one or more of its operands is true. It evaluates two expressions and returns true if at least one is true, otherwise, it returns false. This operator is frequently used in conditional statements to execute code when one of multiple conditions is satisfied.
The Logical OR Operator can be used on non-boolean values but it has a lower precedence than the AND operator.
Syntax:
a||b
Example 1: We will use the OR operator on normal values in this example.
JavaScript
console.log(true || false);
console.log(false || false);
console.log(1 || 0);
console.log(1 || 2);
console.log("1" || true);
console.log("0" || true);
true false 1 1 1 0
Example 2: In this example, we will use the OR operator on function calls.
JavaScript
function a() {
console.log("welcome")
return true;
}
function b() {
console.log("Hello")
return false;
}
console.log(a() || b());
Supported Browsers:
We have a complete list of JavaScript Logical Operators, to learn about those please go through JavaScript Logical Operators article.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4