![]() | MSc-IT Study Material June 2010 Edition Computer Science Department, University of Cape Town |
So far we have used the window.confirm() method that is guaranteed to return either true or false. In a more general case, you will obtain true / false values by comparing two or more values.
Of course, you need to be able to compare all kinds of values and make a variety of comparisons. Here are the main operators for doing, which should be familiar to you from the Java module:
Operator | Example | Meaning |
---|---|---|
== | a == b | equality between any two values; returns true or false (example tests for a being equal to b) |
!= | a != b | inequality between any two values; returns true or false (example tests for a not being equal to b) |
=== | a === b | identity between any two objects; returns true or false (example tests to see if a refers to the same object as b) |
!== | a !== b | non-identity between any two objects; returns true or false (example tests to see if a does not refer to the same object as b) |
< | a < b | less than between any two values; returns true or false (example tests for a being less than b) |
<= | a <= b | less than or equal to between any two values; returns true or false (example tests for a being less than or equal to b) |
> | a > b | greater than between any two values; returns true or false (example tests for a being greater than b) |
>= | a >= b | greater than or equal to between any two values; returns true or false (example tests for a being greater than or equal to b) |
&& | a && b | logical 'and' between two Boolean (true/false) values (example returns true only if both a and b are true, and false otherwise) |
|| | a || b | logical 'or' between two Boolean (true/false) values (example returns false only if both a and b are false, and true otherwise) |
! | !a | logical 'not' of one Boolean (true/false) value (example returns false if a is true and true if a is false) |