JavaScript Tutorial – Comparison and Logical Operators

Comparison and Logical operators return either true or false.

Comparison Operators

Given x = 6, see following examples:

Operator Description Comparing Returns
== equal to x == 8 false
x == 6 true
x == “6” true
=== equal value and equal type x === 6 true
x === “6” false
!= not equal x != 8 true
!== not equal value or not equal type x !== 6 false
x !== “6” true
x !== 8 true
> greater than x > 8 false
< less than x < 8 true
>= greater than or equal to x >= 8 false
<= less than or equal to x <= 8 true

Logical Operators

Given x = 6 and y = 3, see following examples:

Operator Description Example
&& and (x < 10 && y > 1) is true
|| or (x == 5 || y == 5) is false
! not !(x == y) is true