Open In App

What is the use of || Operator in JavaScript ?

Last Updated : 12 Feb, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

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); // Output: true
 
result = false || false;
console.log(result); // Output: false
 
result = true || true;
console.log(result); // Output: true


Output

true
false
true

Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads