This lesson is all about comparison operators.
We're going to look at Bulleen values, Truthy values, family values and a whole bunch of really neat
things.
So we did see earlier that we did use a comparison operator where we looked at the evaluation of content
and seeing whether it's true or false when we are looking at booleans.
So this is what a comparison operator does, is it allows us to ask a question and apply some logic
so we can even do things like equal to which we've seen we can see greater than less than and these
all return boolean values.
So we're asking ourselves the question, is this comparable to that?
And if it is, then we get a true value, and if not, then we get false.
So they can only be one or the other.
And those are where the booleans really shine.
And also notice that when we do equal to that, we have two equal signs, sometimes three equal signs.
If we're also including the data type.
And this is important to note as when we're doing one equal sign, that's an assignment value.
So that's an assignment operator and that's assigning a value.
So to is to do the comparison so you can also use and combine and compare the two.
So opening that up in the Mozilla developer network.
So we've got all the different operators there and the assignment operators, their compound assignment
operators that we've already seen.
And then this is where we're looking at the comparison operators.
So they're we've got the equal sign returns, too, if both are equal and they've got some examples
here.
So if three is equal to var one and if our one is actually three as well, that's good.
Come back.
True, otherwise it's false.
We also have a not equal two, which is interesting because all you do is place the explanation mark
plus the equals sign.
So that also is looking for a true value.
And if it's true, then it's going to run the first block a code within the condition.
So that is something that if we've got three, not equal to four.
And what's the answer to that?
That's true.
There's the strict equal.
So this is also considering the data type.
So meaning that if VAR is equal to the text, the string three and we've got a number three, then on
those two equal sides, they are going to be equal.
It's going to come back.
True.
But on the three equal signs, it's not going to come back.
True.
It's going to be false.
And you can try all of this stuff out in the console so we could look at things like three equals three.
And of course, that comes back.
True.
And if we do three equals and this is a string value that also comes back.
True.
And now if we try it with the third equal sine we see it comes back false.
Three is not equal to and we do four.
So that comes back true.
And you could have some fun with this, play around with it, try out all the different values.
So we see that that also returns back.
True.
And then within the statement then if we do return back true.
Then that's when we run the function.
You can also try different values.
So you can say three is greater than six, which is false.
We know that six is greater than three and that comes back true.
70 is greater than or equal to 70 and that comes back true.
So we know that 70 is not greater than true.
So it comes back false.
So there's a number of different combinations you can do and it really does take a little bit of time
to get more familiar with these.
This is where we've got the less than or equal to greater than or equal to.
And they've got examples of how they work.
If we're just doing the less than or greater than that, we only have the one simple there.
We can also include the not so not within strict as well as not with an equal.
So there's quite a few options and we can do a whole bunch of different types of comparisons.
So what's being returned back is either a truthy or falsey.
And we also saw this earlier when we were doing comparison between what boolean values, when we were
adding them together.
So we saw that booleans are either true or false and they could also be seen as a one or a zero and
also values that are undefined.
So if we have an undefined or a null or a zero or any NP being returned back for the variable, then
that's going to come back as false.
And otherwise, if we do have them and they are equal values, then they are true.
So if it has a value, it's true.
If it's set to true, it's true.
And if it's got a value of one, then that's true.
So those are the true things and the other ones were the falsies.
So what we need to do in this challenge is check to see if a number exists and also check if it is greater
than 50.
So a message in the console.
So first we're going to check to see if it exists for a variable.
So get a variable, assign a value to it and do a condition checking to see if it's there and if it
is output a message.
And if there's no value, then we can do no doesn't exist.
So use some of the.
Falsies in order to indicate that it's not there, so null, zero false, et cetera, and then also
check to see if the value is greater than 50.
And if it is, then I'll put a message into the console so you can pause the video.
And this is the solution to the challenge.
So go ahead and pause the video and write up the solution within your editor.
And I walk you through it coming up.
Let's begin.
So first of all, we need to have a number that we're going to be using so we can use five as our number
that we're checking and we're going to check to see if none exists.
And if it does, then we're going to run this blockquote and this is where we've got our console message.
So if Chuck NUM exists, we can write check.
None is true.
So whatever it's returning back as true, then we get this message and next we want to also check to
see if Chuck Numb is greater than 50.
And I would put a message if it is greater than 50 and then we'll update the value of check number.
And remember, it's even if it's 50, we're checking to see.
So 50 is not greater than 50.
So that's still going to be false.
So keep that in mind as well.
And then just to clarify what number we are working with will output in the consoles.
We see that number is true and 55 and that's the number.
So we're not seeing the bigger than 50.
Let's try some of the other falsies.
So set it to zero and we see that check number is not true.
So it's not there.
It's not true.
And you can also add in an explanation, Mark, so that will negate that.
So instead of being false, that will toggle it to be true.
So it's a one little quick trick that you can do as well.
So all of the ones that are null and undefined, it's always going to come back.
And we're not seeing this message being output.
So it's only until we have a value that's held in here.
So even if we have a value of 500, you're going to see that that value is being output.
And here's again, that type conversion where JavaScript is taking this string and it's saying, is
that string larger than 50?
And it's checking to see if it's trying to convert that string.
So first thing it tries to do when it sees a string and tries to convert it in a number and if it works,
then it's going to output it.
But if you have something like test, then of course you can't check to see if test is larger than 50.
So that's not going to come back and that's going to come back as a not a number.
And remember, not a numbers are falsies.
So that's why we're not seeing that output of that statement.
And then lastly, for some bonus marks, check to see if the value of let's turn it back to five.
So it's a string value of five.
So we're going to check if check number is equal to five.
And so what do you think is going to happen here?
Do you think it's going to output that and we'll just put.
Yes, there.
So do you think yes.
It's going to be output in the console or not?
And remember that the three equal signs are different than the two equal signs because that's also looking
for the data type.
So when we have two equal signs, we see us.
When we have three equal signs, we don't see us because that's not going to be a true statement.
So try this out, have some fun with that experiment.
And coming up next, more advanced with our conditions.