Equals (==), not equals (!=), greater than (>), lesser than (<) - Javascript comparison operators cannot get more simple.
Let’s dissect these operators a bit.
Comparison operators are the ones that you use to.. well, compare.
For example:
|
|
The expression within brackets is evaluated to true
or false
based on operator precedence.
A succinct representation of the above totally real-world problem will be -
|
|
Equality operator works similar to the above, but has a ‘double equals’ in the expression.
|
|
A single =
will result in assignment rather than comparison.
Since we are dealing with Javascript, types can be an advantage or confusing depending on who you ask. To avoid unexpected issues in the above comparison, it is typical to compare the value and the type.
|
|
The opposite of equality is more prevalent on this planet and is depicted as -
|
|
When it comes to comparing greater or lesser of the values, it is more common to say ‘greater than or equal to’.
|
|
You can combine the different operations as well - that is for a different day since I have overdosed on coffees for now.