If statements need Boolean values between those brackets
and we also called those values just booleans
and that's another value type besides strings
and numbers and objects and arrays,
Boolean values are a special value type
that have exactly two possible values, true or false.
So it's like yes or no, just to that,
it's called true and false.
And these two values are our Boolean values,
we can work with in JavaScript.
So whereas a number can be any number
and a string can hold any texts.
A Boolean value can only hold either true or false.
And these are useful, these values,
if we have a yes or no question.
And when do we have such a question?
Exactly. If we have an "if statement",
because we want to execute some code,
to code inside of these curly braces in this if statement,
if a certain condition is met. So if this year says, yes,
then we want to execute the code. If it says no,
so falls in the Boolean world,
then we don't want to execute this.
Now we could directly add true here
as a value and very important
Here we don't have quotes because,
we don't want a string like this instead,
true and false are values,
which are built in as keywords like this.
And if I would set this to true then this would execute.
If I now a save that code
and I open my console here, we see how low.
And on the other hand,
if I set this to false and I saved this,
then we don't see anything. Because then, that code in the,
if statement does not execute,
because that does not answer the question,
wherever that code would be executed.
So if that code would be executed with true instead,
it answers it with false, which means no.
So if false then do nothing.
If true, then execute this code.
This is how you can read this.
Now boolean values are super important in programming
because we need them for control structures like this,
because we need them for "if statements".
And as you will see in most programs that you write,
you will have some parts of your code
that are actually conditional,
that need "if statements" so that you can control
which code should run, and if it should run at all,
but you will typically not.
Hard-code true or false into your if statement as we are
currently doing it, why not?
Well, because then the entire if statement is redundant.
This will always be true, and this will always be false.
So that's not too useful.
I only did that to introduce Boolean values
In stat, you will typically derive Boolean values
with help of so-called comparison operators
and also sometimes with logical operators.
And I will, of course explain both types of operators.
Up to this point, we did learn about those moth operators
and the concatenation operator does plus,
which we can use on strings
comparison and logical operators
are additional sets of operators,
which we can use in Java script.
But the whereas mathematical operators yield us numbers
and the concatenation operator returns a string comparison
and logical operators will actually give us Boolean values.
And let's start with comparison operators here.
Here, we got these operators,
which we can use to compare values with each other.
The first set of operators here is the equality operator
and there we have two kinds of equality operators
with two and three equal signs.
And I'll show you the difference in a second,
but basically we use these operators
if we want to compare two values for equality.
So for example,
if we would want to check whether two is equal to two
or two as a string, as equal to two,
and you see that would actually give us false
if we use that triple equals on operator.
But again, I will explain it in greater detail soon.
And you'll see a couple of other
examples down there as well.
This equality operator can be used to compare
numbers with numbers, strings with strings,
numbers with strings and a couple of other values as well.
It also has a couple of gotchas, but again,
we will see that through out the course.
And in general, the deeper you dive into JavaScript,
the more you will learn about those gotchas,
but it generally works quite straightforward.
You can use it to compare values for equality.
And of course the examples here,
I have hard-coded values only in reality,
you would typically compare values that are entered
by a user in some input field,
from what you've got the value or what you fetched
from some website or anything like that.
Because otherwise, of course, if you hard code the values,
you already know the answer in advance as a developer.
These are really just examples here.
Now the next set of comparison operators are these
greater than, lesser than,
greater or equal and lesser or equal operators,
which allow you to do these exact operations where you
can check whether five is greater than three and so on.
It is worth pointing out that you can also use these
operators on strings. And they're A would for example,
be smaller than B because it comes earlier in the alphabet.
So that's all the worth mentioning here.
Now, the last set of comparison operators,
which you see here are negation operators
or operators that yield the inverse of what you're checking.
So you can check if something is not true.
And you'll see a couple of examples here.
Please note that in the first line,
I'm also using brackets so that for smaller,
four is evaluated first and that would
normally yield false because four is not smaller than four,
but with the negation operator,
the exclamation mark here I then get the inverse of bet.
And the inverse of false is true.
And that's how we derive that value.
And that's also sometimes exactly what you need.
Now, Sometimes you don't just have one check that
you want to perform, but multiple checks.
And then it's the overall result of combining
all those checks and they have for combining
all those Boolean values, which result from these checks.
And that's exactly where logical operators can help you
Here, we got two kinds of logical operators.
We got the and and or operator and with,
and we get true if both compared values are true
and here are some examples
for how that would behave
and with the, or operator we get true.
If one of the two values is true.
So here it's enough.
If one of them is true and you'll see some examples here,
basically the same examples as on the left, just with,
or instead of, and, and that's of course,
just an overview and a summary.
We are now going to explore these operators and play around
with them in code and then see how we can use them in
conjunction with if statements
to do more useful things there