const phoneNumber =345
console.log(phoneNumber === 345) //output is true
console.log (
phoneNumber ==(123||345||567),
); //output is false
Or operator is not showing the proper output , it should show true instead of showing false in second console
The behavior you're observing is due to how the logical OR (||) operator works in JavaScript, not due to a malfunction or bug.
In JavaScript, the logical OR (||) operator returns the first truthy operand it encounters, or the last operand if none are truthy. When used in the context of your example, it doesn't compare phoneNumber to each of the three numbers (123, 345, 567) individually. Instead, it evaluates the expression (123 || 345 || 567) first, and then compares the result of that expression to phoneNumber.
Let's break down what happens in the second console.log statement:
The expression inside the parentheses is evaluated from left to right: (123 || 345 || 567). Since 123 is truthy (in JavaScript, all numbers other than 0 are considered truthy), the OR operation stops at the first operand (123), and the entire expression evaluates to 123. Therefore, the comparison effectively becomes 345 == 123. Since 345 does not equal 123, the comparison returns false. This is why the output is false instead of true. If you want to check whether phoneNumber matches any of the three numbers, you need to compare them individually, like this:
console.log(phoneNumber === 123 || phoneNumber === 345 || phoneNumber === 567);
This approach compares phoneNumber to each of the three numbers separately and uses the OR operator to check if any of those comparisons are true. If phoneNumber matches any of the specified numbers, the result will be true.