Comparison and logical operators are used to test true or false.
Comparison operators
Comparison operators are used in logical statements to determine whether a variable or value is equal
Instance
Logic and
<script language= "JavaScript" >
<!--
x = 3;
if ((2==x) && (x=5)) {
document.write ("The && evaluated True!<br>");
}
Else
{
document.write ("The && evaluated False!<br>");
}
document.write ("x=", X, "<br>");
-->
</script>
and Conditions and operators
var btrue = true;
var bfalse = false;
var bresult = btrue && bfalse;
Logical non-not
<script language= "JavaScript" >
<!--
Thetruth = new String ("1");
Thereversetruth =!thetruth;
document.write ("Thetruth =", Thetruth, "<br>");
document.write ("Thereversetruth =", Thereversetruth);
-->
</script>
Logical OR Operator | | (Logical OR)
var btrue = true;
var bfalse = false;
var bresult = Btrue | | Bfalse;
Let's look at a reference table
operator |
Description |
Example |
== |
Equals |
X==8 to False |
=== |
Congruent (value and type) |
X===5 is true;x=== "5" to False |
!= |
Not equal to |
X!=8 is True |
> |
Greater than |
X>8 to False |
< |
Less than |
X<8 is True |
>= |
Greater than or equal to |
X>=8 to False |
<= |
Less than or equal to |
X<=8 is True |