var a = '1';
console.log(a == ('2'||'1')?'hi':'hello');
Doing so the condition get failed as a = 1 .
It is comparing a's value 1 with 2 as this condition failed. so it always print hello.
Is there any way to check for value('1') also which is after "||" so that it print hi?
Either list the different possibilities out separately:
Or use an array and
.includes:The problem with
('2'||'1')is that the whole section there gets evaluated to a single expression before the comparison againstais made, and||will evaluate to the initial value if it's truthy. So('2' || '1')resolves to'2'.