There is one interview question below. The logical AND of two truths should be true. But the output is 3. Why?
var a = 2;
var b = 3;
var c = a && b; // value of c = 3
console.log(c);
There is one interview question below. The logical AND of two truths should be true. But the output is 3. Why?
var a = 2;
var b = 3;
var c = a && b; // value of c = 3
console.log(c);
Check this out.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Logical_Operators
If you use && with non-boolean values, it returns the first element if it can be converted to false. If it cannot converted to false, it returns second element