I’ve stated this before, and I’ll say it again.
- Uppercase letters are less than lowercase letters.
- The size of the letters gets bigger from “a” to “z.”
But here’s something interesting.
It turns out that capitalization takes precedence over the actual order of the alphabet!
So if you’re comparing letters of the alphabet, you need to first consider whether or not it’s capitalized, and then consider the order where that letter is in the alphabet.
How to use the “greater than” operator
The greater than operator is symbolized as >.
Here’s an example of a true expression using >.
console.log("z" > "a");
And the output is:
How to use the “less than” operator
The less than operator is symbolized as <.
Check out the example below.
console.log("Z" < "a");
And the answer is:
Surprise! Didn’t I tell you above?
First, consider the capitalization, then the position of the letter in the alphabet.
In that case, a capital Z is smaller than the lowercase a.
There’s nothing more to it.
And that’s what < means.
“Z is less than a.”
How to use the “equal to” operator
The equal to operator is symbolized as ==.
I think this one is as clear as day.
The two things have to be exactly the same, and that also means you have to take into consideration the capitalization.
Let’s show you an example:
console.log("a" == "a");
The output is:
If it were anything else other than “a” compared to “a,” it’d be completely false!
Example 2: The exception is that NaN is not equal to NaN!
console.log(NaN == NaN);
You probably already guessed what the answer to this is.
NaN is suppose to be a number but nonsensical. In essence, it’s one NaN isn’t like any other number or NaN either.
Just remember that.
How to use the “not equal to” operator
The not equal to operator looks like this !=.
I think most of us get the point.
console.log("a" != "A");
And the output is:
Yep! That’s exactly what we’re expecting.