Welcome back to Lesson eight, Truthy and falsey, values and equality operators.
So we looked at equality for comparison, for resolving true and false last time.
But now we're going to bring in not just true and false, but truthy and false values.
So Truthy and false values will resolve to true or false.
And there are some things that if you just if the value is one of these things, an empty string or
the number zero or the values null or undefined or the value not a number.
So it's a no type, but it's trying to understand it as a number.
But the value is actually not not a number that it can represent these if you just check to see their
value.
As far as Boolean logic, it's going to compute their value as false.
OK, obviously if you printed something out that had this has its value, it would just give you this
as the return.
But if you're going to do a comparison between two things, it's going to understand them in their truthy
value as falsey.
And then there are some things here, like five being equal to five.
This one is a string and this one is a number.
If you check both of them with this equals, it's going to say, hey, these are the same value, even
though they're not the same data type.
If I compare them as the same value, then yes, that's true.
If you say, are they exactly the same, then no, it's going to be like this one is a string.
That one's a number.
You can't convince me those are the exact same thing.
OK, OK, so let's play with this in JavaScript a little bit.
Let's just take let's just take this number and set it to fifty nine, OK?
And let's do a little if if, Noam.
So we're checking if this value and when you do if whatever's in parentheses will be evaluated for it's
true or false value and so is fifty nine true?
Well, yeah, it's Truthy because it's not zero.
Zero is falsey, which means it will be interpreted by a boolean logic checker as false, but any other
number is going to be resolved as true.
OK, so let's just log.
Variable is defined.
And then we can do an else.
And then check the value here,
if it's not true, then let's just set this message that we're going to get variable has not been defined.
OK,
let's be extra clear about the.
All right, so taking this, let's go ahead and print that out.
Variable is defined.
Why?
Because we gave it a value.
Now, what if we gave it zero?
We initialized it with zero.
What's going to happen now?
Variable has not been defined.
So we got a typo here.
Variable has not been defined interesting, so it's technically defined.
So we could clarify this as a false policy value.
Now, obviously, we can give things a true value directly, so we could just say, hey, it's true
or we could just say it's false.
But if we give it any one of these five things, zero.
Or No.
Or undefined, so we just don't define it or we give it an empty string.
That has a true value because the string is not empty.
There are two characters in here, so the spaces mean something, even one space means something, but
make it a completely empty space with nothing between those quotes and it's false.
Interesting, huh?
Or we could do it as some some value.
That's not a no.
Hi.
Check that that's false, but if we do some number, that's actually a number that's true.
OK, so then we just tested for Truthy and false values and we tried a few different iterations to show
you how those work.
OK, and again, with the quality operators, just to recap those, if we wanted to give you the example
here, let's just say this one is fifty nine, OK?
And then we can use if and all statements to say, OK, this is exactly equal to fifty nine, then we
can say OK, yes, variable has a value of fifty nine.
And this one does not have a value of fifty nine.
OK, it has a value of fifty nine.
What if we change this to
a string called fifty nine?
That won't work.
It does not have a value of fifty nine because it's the wrong data type strings are not numbers, but
they can be interpreted as numbers if you use this comparison operator, says a similarity operator,
and we check it.
The value inside the quotes is the same as the value right here for the number, so it will interpret
it that way.
OK, so that's Truthy and falsey values and the comparison operator for equality.
This is checks for the same value and data type, and this is just producing value only.
All right, see you in the next video.