JavaScript Comparison Operators

JavaScript Comparison Operators are used to compare two values. The comparison returns a boolean value of either true or false. In JavaScript, you can use these operators to make decisions in your code. These operators are also known as relational operators and are used to compare values of different data types.

There are six comparison operators in JavaScript:

  • == equal to
  • != not equal to
  • === equal value and equal type
  • !== not equal value or not equal type
  • > greater than
  • < less than
  • >= greater than or equal to
  • <= less than or equal to

The == operator compares two values and returns true if they are equal. The != operator, on the other hand, returns true if the values are not equal.

The === operator is known as strict equality. It checks not only for equality of values, but also for equality of data types. For example, 3 === 3 returns true, but 3 === "3" returns false.

The !== operator is the opposite of the === operator. It returns true if the values or the data types are not equal.

The >, <, >=, and <= operators are used to compare values and return true or false based on whether the values meet the conditions.

It's important to keep in mind that comparison operators only compare the values and return a boolean value. They do not change the values being compared.