Comparison in JavaScript

 

In JavaScript, you can use comparison operators to compare values and produce a Boolean result (either true or false). Here are some common comparison operators:

  • == : equal to (compares the values, but not the data type)
  • ===: equal to (compares both the values and data type)
  • !=: not equal to (compares the values, but not the data type)
  • !==: not equal to (compares both the values and data type)
  • >: greater than
  • <: less than
  • >=: greater than or equal to
  • <=: less than or equal to

For example:

javascript

var x = 5; var y = 10; console.log(x == y); // false console.log(x === y); // false console.log(x != y); // true console.log(x !== y); // true console.log(x > y); // false console.log(x < y); // true console.log(x >= y); // false console.log(x <= y); // true

In the code above, we have two variables, x and y. We use the comparison operators to compare the values of x and y and print the result to the console. In this case, x is less than y, so x < y and x <= y both return true, while x > y and x >= y both return false.

0 Comments

You can use the contact form below to send us a message

We would love to hear from you! If you have any questions, comments, or suggestions, please feel free to get in touch with us.