Skip to main content

Using Comparison Operators

You use comparison expressions to compare the values of two or more numbers, strings, variables, properties, or function results. If the expression is true, the expression result is set to the Boolean value true; if the expression is false, the expression result is set to the Boolean value false. You'll use comparisons constantly in your JavaScript code, so it's important to understand what they are and how you use them.

Operator Name Example Result
== Equal 10 == 4 false
!= Not Equal 10 != 4 true
> Greater Than 10 > 4 true
< Less Than 10 < 4 false
>= Greater Than or Equal To 10 >= 4 true
<= Less Than or Equal To 10 <= 4 false
=== Identity 10 === 10 true
!== Non-Identity 10 !=== 10 false


Example: comparing two values.

 
<script language="JavaScript" type="text/javascript">
<!--
var value1 = prompt("Enter the first value:", 10)
var value2 = prompt("Enter the second value:", 5)
var comparison_result = value1 == value2
alert(comparison_result)
//-->
</script>
 

Next: Logical Expressions