What is the use of || Operator in JavaScript ?
Last Updated :
12 Feb, 2024
In JavaScript, the ||
operator is known as the logical OR operator. Its purpose is to perform a logical OR operation between two operands. It returns true
if at least one of the operands is true
, and false
otherwise.
Example: Here, true || false
evaluates to true
because at least one operand (true
) is true
. In the second example, false || false
evaluates to false
because neither operand is true
. In the third example, true || true
also evaluates to true
because both operands are true
.
Javascript
let result = true || false ;
console.log(result);
result = false || false ;
console.log(result);
result = true || true ;
console.log(result);
|
Share your thoughts in the comments
Please Login to comment...