Now these symbols, such as the greater (>) or the lesser (<) than or the three equals signs (===), are known in programming
as, Comparatives, because they allow us to compare two different values.
So we've seen and used the three equals signs.
And this is checking whether if the left-hand side is equal to the right-hand side.
Now you can also use an exclamation mark and two equal signs (!==) to check whether if the left-hand side is
not equal to the right-hand side, as well as whether if something is greater (>) than something else, or if something
is lesser (<) than something else or greater than equal (>=) or lesser than equal (<=).
And these comparatives give our conditionals, like if and else statements, a lot more flexibility.
Now, some of you might have seen another type of equality comparator.
So instead of using a three-equal sign sometimes you see people using two equal signs (==).
Now, there's a big difference however between the two of these.
So let's say we have a variable a and it's equal to 1 and then we have a variable b that's equal to
the string 1.
So this is 1 as a piece of text essentially, and they have different data types,
because if we say typeof(a) we get "number", and typeof(b) we get "string".
So at this point if we check to see if (a === b), then if it's true we will get console.log("yes')
;
and if it's false then we will get console.log("no");
So if I go ahead and hit Enter right now, then you can see that we get "no", a does not triple equal b.
But, however, if I was to modify this and change it to if a is a double equal to b and I hit Run, then
you can see we get
"yes"
in this case.
So the important difference between three equal signs and two equal signs is that even though they both
check for equality, with three equal signs
itâ€™s also checking to see that the data types are matching, whereas with two equal signs it doesn't care
about the data types.
So let's head back to our love calculator and maybe one more thing that we could ask of it.
What if we could separate our love score ranges a little bit more finely?
So, for example, if we could have a different message for people who got between 1 and 30, then people
who got between 30 and 70, and those who were ultra lucky and got between 70 and 100.
How would we be able to do that?
Well, we would have to learn how to combine different comparatives, and we'll tackle that in the next
lesson.
So that's all for me for today.
And I will see you on the next lesson.