Learn JavaScript #5 | Boolean Operators

JosephDelgadillo
58 followers
7 Video Views·Aug 16, 2024
Get The Learn to Code Course Bundle!
https://josephdelgadillo.com/product/learn-to-code-course-bundle/
In the 5th episode of this JavaScript tutorial series, we will cover boolean operators. Booleans are used to compare whether two statements are true or false. In JavaScript, one equals sign is used for assignments, and two equal signs are used for comparisons.
Learn more about my courses at https://josephdelgadillo.com
I think we can actually work directly in the console for now because we're not
building anything elaborate, so let's go ahead and write some more code. We're
going to be talking about booleans in this video. So, a boolean is a type,
just like strings and integers are types, boolean is a type that's used for
certain purposes. For instance, I mean you can't say you can't really compare
different types unless its float and integer and you can compare those both
as numbers, but you can't compare a boolean like true or false
to text. You can't say if text equals, or if text is greater than true. Like
there's no greater than true, true is just true. So, let's go ahead and create a
variable called iLikeCheese, and that's going to be set to true. Now, you'll
notice that true is it's a key word, it's a boolean operator, so it's going to be
color-coded like variable in most cases, and it's just a lowercase word. You don't
put it inside text and it becomes a string but we're interested in using as
a boolean, and so we can check if something equals something else by
saying iLikeCheese == true. This will return true because it does
equal that. Or, does it equal true in text? Now, as I said true as a boolean does not
equal true as text because true as text is not a boolean operator. There's no way
to compare the two because they're so different, and we'll talk more about
comparisons later on. I just wanted to show you guys the difference between a
boolean and a string. Now, you can also set, and maybe I have a bad
experience with cheese and I don't like cheese anymore, we reassign by saying
iLikeCheese = false. So, when you're assigning a variable, or
reassigning a variable, you always use one equal sign. I saw that I used two
here so I just didn't want you guys to get confused as when to use each one. Two
are used for comparisons, one is used for assignments. So, now iLikeCheese now
becomes false. These are two boolean operators and that's all we're covering
in this video, I guess. In the next video, I think we're good to move forward to
more advanced things, hopefully if conditions, and for loops, and stuff like
that.
