When I use the logical operator && between two strings, why does it give me the second string as output:
console.log("" && "Dog"); // ""
console.log("Cat" && "Dog"); // "Dog"
I realize that the with the exception of 0
, false
, null
, undefined
, ""
and NaN
, everything else is evaluated as a boolean true in a logical expression like the one above. But why is the output the second string and not the first? And why is the ouput not just "true" since it is being evaluated as a boolean expression?