Think of && in JavaScript like this (based on ToBool from es5 spec )
function ToBool(x) { if (x !== undefined) if (x !== null) if (x !== false) if (x !== 0) if (x === x) // not is NaN if (x !== '') return true; return false; } // pseudo-JavaScript function &&(lhs, rhs) { // lhs && rhs if (ToBool(lhs)) return rhs; return lhs; }
Now you can see that ToBool("Cat") is true , therefore && will give rhs which is equal to "Dog" , then === does "Dog" === "Dog" , which means that the line gives true .
For completeness, the operator || it could be considered
// pseudo-JavaScript function ||(lhs, rhs) { // lhs || rhs if (ToBool(lhs)) return lhs; return rhs; }
source share