JAVASCRIPT Tutorial

Comparison Operators

Comparison operators are used to compare the values of two operands. They return a Boolean value (true or false) based on the result of the comparison.

Key Concepts:

  • Equality (==, ===): Checks if two operands are equal in value.
  • Inequality (!=, !==): Checks if two operands are not equal in value.
  • Greater Than (>): Checks if the first operand is greater than the second.
  • Less Than (<): Checks if the first operand is less than the second.
  • Greater Than or Equal To (>=): Checks if the first operand is greater than or equal to the second.
  • Less Than or Equal To (<=): Checks if the first operand is less than or equal to the second.

Javascript Example:

// Equality
console.log(1 == 1); // true
console.log('1' == 1); // true

// Inequality
console.log(1 != 2); // true
console.log('1' !== 1); // true

// Greater Than
console.log(2 > 1); // true

// Less Than
console.log(1 < 2); // true

// Greater Than or Equal To
console.log(2 >= 2); // true

// Less Than or Equal To
console.log(1 <= 2); // true