Now to play around with those operators,
I'm back here in the console,
this JavaScript console and the dev tools.
Since we can quickly enter a code like this here
and instantly see the result,
which is more convenient than typing it here
and then executing the code and then seeing it here.
So that's why we'll continue here.
And let's play around with those various operators
I showed you.
And for example, you see,
we can compare numbers with each other for equality.
And I did mention
that we have two kinds of equality operators there
with two and with free equal signs.
Now, what's the difference?
The difference is that
if you use the one with two equal signs,
you compare devalues only.
And as a consequence, if you would compare to number five
with the string five, with the two equal sign operator,
you would get true.
With the triple equal sign operator,
you instead, also the check for type equality.
So for this comparison, you get false
because whilst the value is to same five,
the value type is not the same.
One of them is a number and one of them is a string
and these are different value types as you learned.
And therefore it is generally considered a best practice
to always use to triple equal sign operator,
because typically you should compare equal types.
Of course, if you know
that you need to compare a string to a number
and you want to check for value only
it is fine to use the double equal sign operator as well.
Now, we also learned about the negation operator
and there we could check if five is not equal to five,
which of course is false because they are equal.
And for example, checking a four is not equal to five
therefore would yield true.
And here we would also actually get true.
If I check for five, not being equal to five,
if the second five is a string
and the first one is a number.
So that's how we could use this negation operator.
It also exists on a one equal sign only though.,
and then here I would get false because now again,
we only have a look at the value.
Now, besides equality or not equality,
we can also check for values being greater or smaller.
And for example, we can check if three is greater than one,
and if four is greater than six, which of course is not,
we can check for 'a' being greater than 'b',
which is not because 'b' comes after 'a' in the alphabet.
And we can check if 'cb' is greater than 'ab', which it is
because if you have multiple characters in the string,
the characters are compared character by character.
So first 'c' and 'a' is compared
and if we have a winner there, then we're done.
And only if they would be equal,
it would move on to the second character
and compare those with each other.
But here 'c' is greater than 'a',
and that's why we overall it gets true for this comparison.
And we can also check for equality so greater or equal
and that would also behave
just as you would probably expect it.
Now it is worth mentioning
that you can't combine the negation operator
with those kinds of comparisons just like this.
So you can't do that.
You see, you get an error.
Instead here, you would first execute this comparison,
wrap ii in brackets,
and then add your negation operator in front of it
because you can always use this negotiation operator
to convert a true value to false or a false value to true.
And that's essentially what we're doing here.
Then we are first deriving a true or false value,
and then we're getting the inverse of it.
Now that we're are comparison operators,
we also got the logical operators.
And here we got and, and, or.
And here, the idea is simply that
sometimes we have multiple combined conditions.
For example, we could be checking if five is equal to five,
and if three is equal to three,
and that would return true
because both individual expressions here yield true.
If we would have at least one expression that yields false,
the overall expression would yield false
with that end operator.
With the or operator on the other hand,
that is enough if at least one of the two expressions
yields true.
So there, if we had basically the same line of code,
but with the, or operator, we would get true now
because at least one of the two yields, true.
Of course, if both yield false,
for example, if I changed this five to a six,
then we would also get back false as an overall result here.
Now it's also worth mentioning
that you can combine as many comparisons as you want.
For example, we could be saying
that we wanna check if two is equal to two,
or if two is equal to three,
and we wanna check if five is equal to six.
And what you see is that if I would execute this,
it would work.
And I would get true as an overall result
because by default,
this will be evaluated or read like this.
JavaScript will first evaluate this part
with the end operator,
since this has higher priority in JavaScript
and therefore the result of this comparison will be false
because both conditions here actually yield false,
but even if just one of them would yield false,
this would still overall yield false
because that's how the end operator works.
But then you see that the overall result is true,
and that tells us that JavaScript then
takes the result of this second comparison here
with the end operator
and of course combined stays with the first comparison here
with the or operator.
And you learned that the effort is overall will yield true
if at least one of the two operations
that are compared with that or operator yield true.
And that's the case,
because this first operation yields true.
Now, just like in regular moth,
you can override is built in priority by adding parentheses.
If you wanna say that you don't want this second part here
to be evaluated first,
but instead you first wanna check this or operation
and then combine that
with the result of this last comparison,
you can do this by simply adding parentheses here.
Now you see, we overall get false
because now JavaScript will first of all,
make this evaluation here and that of course yields true
because well, both sides have or return true,
but it would even be enough
if just one of them would yield true.
But then the overall result of this first comparison
of this first evaluation here
is combined with that last comparison with the end operator
and therefore we overall get false
because this yields false, five is not equal to six.
And you learned that for 'n',
both sides need to yield true and that's not the case here,
hence we get false.
So you can combine as many comparisons as you want
and you now also learned about the priority
of the different operators.
And that said four days introduction to booleans
and this comparison of logical operators.
Of course, playing around with numbers
in the console like this,
is not what we would do in real apps,
but it is useful to understand these operators.
I'm just giving you this overview right now,
so that we can then use all these features
later throughout the course.
But of course, there, you will then also see them
in more realistic scenarios.
For example,
back here in this example code I started with earlier.