I'm trying to compare to boolean value in a if
.
I would like to do something like this:
value1 = false;
value2 = true;
if (value1 === value2) {
... Some code ...
}
In JAVA you can use Boolean.compare(boolean a, boolean b)
, but I can't find something equal in TypeScript.
For context, Boolean.compare(boolean a, boolean b)
returns:
- 0 if
a
is equal tob
, - a negative value if
a
is false andb
is true, - a positive value if
a
is true andb
is false.
Thanks for you help
Edited: to show the message I get
This condition will always return 'false' since the types 'true' and 'false' have no overlap
===
is how to compare two boolean values.===
checks for equality.Boolean.compare
checks for ordering (returns less than zero ifa
isfalse
andb
istrue
, zero if they are equal or more than zero ifa
istrue
andb
is false - is that the behavior you're looking for?Boolean.compare
to your question since it seems you're being downvoted due to being misunderstood.