Comparision Operators

When writing conditional statements, we need to use different types of operator to compare values.

List of some handy comparision operators:

  • Less than <

  • Greater than: >

  • Less than or equal to: <=

  • Greater than or equal to: >=

  • is equal to: ==

  • is not equal to: !=

Comparision operators compare the value on the left with the value on the right.

Example:

console.log(10 < 11);

// Output: true

console.log('apple == 'oranges');

// Output: false

Example:

let sale = true;

sale = false;

if(sale) {
  console.log('Time to buy!');
} else {
  console.log('Time to wait for a sale.');
}

// Output: We can eat later!

Last updated