I was reading some tricky javascript output question and found that
console.log(2 && 3) is 3
There is no explanation for the same. Shouldn't it be true
?, as value of both the numbers being non zero should be type casted as true
I was reading some tricky javascript output question and found that
console.log(2 && 3) is 3
There is no explanation for the same. Shouldn't it be true
?, as value of both the numbers being non zero should be type casted as true
It's just the way the language works. It is well documented.
Per MDN:
Logical AND (expr1 && expr2) Returns expr1 if it can be converted to false; otherwise, returns expr2. Thus, when used with Boolean values, && returns true if both operands can be converted to true; otherwise, returns false.