Let's var a = "first", b = "second", c = "first";
.
Expression a == c
returns true
, (of course!); a == c
is true
too.
Then why does a == a == c
return false
?
Example
var a = "first", b = "second", c = "first";
write( a != b != c );
write( a == b != c );
write( a == b == c );
write( a != b == c );
write("");
write( a == a == c );
// -------------------
function write(val) {document.querySelector("console").innerHTML += "<hr noshade size='1px' color='#eee'>" + String(val);}
<console></console>
Because what is really happening is this:
Which is really just:
See Operator Precedence.