I have tried conditional operator inside console.log()
. Less than <
returns correct response but greater than >
returns wrong respon
The <
operator accepts two operands and yields a boolean result. Your code is effectively:
let temp = 7 > 6;
console.log(temp); // true
let result = temp > 5;
console.log(result); // false
The reason temp > 5
is false
is that true > 5
coerces true
to a number (1
), and 1 > 5
is false.
Insead, use &&
if you want a logical AND condition:
console.log(7 > 6 && 6 > 5); // true