Why is the following code created a == 3?
var x = "abc";
var y = 3;
var z = "xyz";
var a = x && y || z;
http://jsfiddle.net/thinkingmedia/qBZAL/
I expected this to result in a == true.
Why does a logical operator evaluate "abc"how true, but not evaluate 3how true. Instead, the result is 3.
Also, if you change y = 0, then a == "xyz"that means it is &&treated 0like false. What happens to treating a number as a number?
What happens here with logical operators?
cgTag source
share