OR(||) Logical Operator in JavaScript
JavaScript logical OR(||) Operator or Logical disjunction Operator operates on a set of operands and returns true even if one of the operands is true. It evaluates the operands from left to right and returns true whenever it encounters the first truthy value otherwise false.
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: In this example, we will use the OR operator on normal values.
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 );
|
Output
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:
- Chrome
- Edge
- Firefox
- Safari
- Opera
We have a complete list of JavaScript Logical Operators, to learn about those please go through JavaScript Logical Operators article.
Last Updated :
27 Dec, 2023
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...