When I use the logical operator && between two strings, why does it give me the second string as output:
I think this is because of nature of logical operator &&. Javascript executes expression "cat" && "Dog" in following way:
Checks the value "cat" - it returns something else than "", 0, null, undefined or false and is truthy. Javascript sees && and so it continues expression and faces string "Dog", which is something else than "", 0, null, undefined or false and is truthy, expression ends and expression returns the last value it checked.
If you replace && with || expressions ends at first truthy value and thats way
var boolean = "cat" || "dog"
returns first value: cat