Not sure this is doable, but I am looking for a truth return if, for example.. var A = 100; var B = 100;
(A == B == 100)
I figured this would return true. Because A == B (they are both 100) and as such, they both equal 100.
But it is always false.
EDIT::: Thanks, Yeah - I appreciate the repsonses.. I was hoping there was some nifty shorhand than doing (A === 100 ) && ( B === 100) etc... But thank all very much.
Not sure this is doable, but I am looking for a truth return if, for example.. var A = 100; var B = 100;
(A == B == 100)
I figured this would return true. Because A == B (they are both 100) and as such, they both equal 100.
But it is always false.
EDIT::: Thanks, Yeah - I appreciate the repsonses.. I was hoping there was some nifty shorhand than doing (A === 100 ) && ( B === 100) etc... But thank all very much.
Share Improve this question edited Feb 18, 2013 at 6:54 james emanon asked Feb 18, 2013 at 6:49 james emanonjames emanon 11.8k11 gold badges69 silver badges107 bronze badges 1- slightly shorter: (A==B) && (A==100) – Udo Klein Commented Feb 20, 2013 at 10:52
5 Answers
Reset to default 13Either it evaluates as
(A == B) == 100
or as
A == (B == 100)
In both cases you pare a boolean with 100. This is of course always false. You want
(A==100) && (B==100)
To see what is going on you might want to run the Example below as JSFiddle:
var A = 100;
var B = 100;
alert("B == 100: " + (B == 100));
alert("A == (B == 100):" + (A == (B == 100)));
alert("A == B:" + (A == B));
alert("(A == B) == 100:" + ((A == B) == 100));
alert("A == B == 100):" + (A == B == 100));
alert("(A == 100) && (B == 100):" + ((A == 100) && (B == 100)));
A== 100 && B == 100
Is what you are looking for.
It translates to true===100
which is obviously false
. You can use a===b && b===100
Because the after the second expression that is (B == 100)
the value of A
it gets pared to boolean
so it would always be false
that is:
A == (B == 100)
Which bees
A == true
Which evaluated to false
So the correct version should be:
(A == 100) && (B == 100)
Live demo
i think it can be interpreted as
(A == B) && ((A == B) == 100)
obviously,it's not true
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745309019a4621888.html
评论列表(0条)