3 min read
These are super handy for decision-making. Let's see which ones we can use:
|Not equal to|
|Strict equal to|
|Strict not equal to|
|Greater than or equal to|
|Less than or equal to|
This operator is used to evaluate two values. However, they don't have to be of the same type. Meaning we can assess if a string is equal to a number!
`5` == 5; // true 5 == 5; // true
But it can also compare strings for instance:
'string' == 'string'; // true 'String' == 'string'; // false
Note: It's capital sensitive, as you can see above!
Following this is the not equal to operator, which can evaluate if a comparison is not correct.
5 != 5; // false 8 != 5; // true '8' != 5; // true 'String' != 'string'; // true 'string' != 'string'; // false
Then we have these two as strict versions, which should be preferred over the top ones. What this means is that it will check against the type as well.
5 === 5; // true '5' === 5; // false
And the same works for the not equal to strict comparison.
5 !== 5; // false 8 !== 5; // true '8' !== 5; // true
Then we have the greater than and less than operators. These can be used to assess if a value is greater or less than the compared one.
Generally, these should only be used with number values.
8 > 5; // true 8 < 5; // false 5 > 8; // false 5 < 8; // true 5 > 5; // false
We can also use the above two comparisons to check whether something hits a threshold.
We want to evaluate if a value is greater than or equal to a certain number?
5 >= 5; // true 8 >= 5; // true
Meaning our number is greater than or equal to 5, which is the case in the above example.
This can also be used for checking less than operations.
5 <= 5; // true 3 <= 5; // true
Thank you for reading, and let's connect!
Thank you for reading my blog. Feel free to subscribe to my email newsletter and connect on Facebook or Twitter
Did you find this article valuable?
Support Chris Bongers by becoming a sponsor. Any amount is appreciated!