What are other JavaScript comparison operators?

JavaScript provides several comparison operators that allow you to compare values. Here are the main ones:

  1. Equal to (==): Compares two values for equality, performing type coercion if necessary.

    console.log(5 == '5'); // true
  2. Not equal to (!=): Compares two values for inequality, performing type coercion.

    console.log(5 != '6'); // true
  3. Strict equal to (===): Compares two values for equality without type coercion (both value and type must match).

    console.log(5 === 5); // true
  4. Strict not equal to (!==): Compares two values for inequality without type coercion.

    console.log(5 !== '5'); // true
  5. Greater than (>): Checks if the left value is greater than the right value.

    console.log(5 > 3); // true
  6. Less than (<): Checks if the left value is less than the right value.

    console.log(3 < 5); // true
  7. Greater than or equal to (>=): Checks if the left value is greater than or equal to the right value.

    console.log(5 >= 5); // true
  8. Less than or equal to (<=): Checks if the left value is less than or equal to the right value.

    console.log(3 <= 5); // true

These operators are fundamental for making decisions in your code, such as in conditional statements and loops.

0 Comments

no data
Be the first to share your comment!