I had checked for many test cases. It's looking if the first value is true and it's returning the second value.
Example:
2 && 5 // --> 5
5 && 10 // --> 10
0 && 2 // --> 0
Why doesn't it return either True or 1?
I had checked for many test cases. It's looking if the first value is true and it's returning the second value.
Example:
2 && 5 // --> 5
5 && 10 // --> 10
0 && 2 // --> 0
Why doesn't it return either True or 1?
Operator: Logical AND (&&)
Usage: 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 are true; otherwise, returns false.
The && operator will return the last value if all other values are truthy, otherwise it will return the first non truthy value. So, as in 0 && 2
, 0
is non-truthy, that gets returned.