Stop Low Resolution Warning Sign

Transcript

Transcript of the tutorial. TOP


          
        
          All right then, gang.

          So we've taken a look at quite a lot of different data types in JavaScript so far Numbers, strings,
          
          null undefined and also arrays, which is a type of object.
          
          Now I want to talk about booleans.
          
          Now Booleans represent two special values in JavaScript, true and false.
          
          So let's have a look at those.
          
          So the first thing I'm going to do is console.log true and false.
          
          Now, these are not strings.
          
          Look right here.
          
          We've not put them in quotes and they're purple.
          
          They're colorized by the text editor because it knows that these are special values.
          
          They are booleans.
          
          So if I save this and see in the console over here, we can see true and false.
          
          Now, if I put these next to actual strings, true and false, these are not the same things.
          
          This is a string which just says true.
          
          And this is a string that says false.
          
          They are not the same as these two things that are not strings.
          
          So when we view them in a console, the console helps us out and it colors these a little differently
          
          from strings.
          
          So we use booleans to evaluate conditions in our code and to check whether certain things are true or
          
          false.
          
          For example, we can perform some methods on strings or arrays or numbers that are going to return to
          
          us a true or false value, a Boolean.
          
          So let's do a few examples of this.
          
          And first of all, I'm going to say let email equal to Luigi at the net ninja.co.uk.
          
          Okay, so now I'm going to use a few different methods on this email thing.
          
          So I'm first going to say let result equal to email dot includes and then we're going to look for the
          
          at symbol.
          
          So this method right here includes we can use on a string to look if a certain character appears in
          
          that string.
          
          Now, if it includes that character in the string, this is going to return true.
          
          If it doesn't, it returns false.
          
          So it returns a boolean either way.
          
          Let me log this to the console.
          
          I'm going to log the result like so save it and preview and we can see true because it does include
          
          that symbol right here.
          
          If I instead do an exclamation mark, it's going to return false because it doesn't include that in
          
          the string.
          
          All right.
          
          Okay.
          
          So now let me create a new variable called names.
          
          Set that equal to an array and we'll put Mario in there and Luigi and also Toad.
          
          Okay, So we have this array of names.
          
          I'm going to come down here and use exactly the same method on this array.
          
          So I'm going to say let result this time equal to names.
          
          Dot includes.
          
          And we're going to look for a particular value inside this array.
          
          So I'm going to look for Luigi.
          
          Now, this should be true because Luigi is an element inside this array.
          
          Okay, So when we use this method on an array instead of a string, it looks inside the array and tries
          
          to match this value to one of the values inside the array.
          
          Now we have to comment this out because we don't want to define result twice, save it and preview and
          
          we get true because Luigi is inside that array.
          
          If I change this to something like Bowser, then it should be false because Bowser is not inside the
          
          array.
          
          Okay.
          
          All right, cool.
          
          So let me comment this out again and this one.
          
          And now what I'd like to do is show you some different comparison operators.
          
          So we'd use comparison operators to compare two things together and they're going to return a Boolean.
          
          True or false?
          
          So let's just go through a few examples.
          
          I'm going to create an age variable, first of all, and set that equal to 25.
          
          And then I'm going to log something to the console.
          
          So we'll say console, dot log, and inside I'm going to say age is equal and that's double equals to
          
          25.
          
          Now notice we're using double equals and not single equals right here.
          
          Single equals sets a value to something like this.
          
          When I use double equals, what I'm doing is saying, are these two things the same?
          
          Is age equal to 25?
          
          So if age is equal to 25, then this is going to evaluate to true and we're going to get that true boolean
          
          log to the console.
          
          So let me save it and preview.
          
          And we see true right here.
          
          Cool.
          
          So what I'm going to do now is just duplicate these onto a new line and we're going to just change the
          
          condition inside here.
          
          So now I'm going to change this to 30.
          
          Is age equal to 30 now that's false.
          
          So we should see false over here.
          
          And we do.
          
          Now let's do another.
          
          So I'm going to say is age.
          
          Now I'm going to replace the first equal sign with an exclamation.
          
          And what this does is negate this.
          
          So it says, is age not equal to 30?
          
          Okay.
          
          Now age is not equal to 30.
          
          So that's going to be true.
          
          This statement, if I change this to 25, then age not equal to 25, That would be false because age
          
          is equal to 25.
          
          That's a little difficult to get your head around at first.
          
          But just remember this right here.
          
          This turns it into a not equal.
          
          So if these things are not equal, then the statement is true.
          
          So if I save it, then we should see true because age is not equal to 25.
          
          That statement is true.
          
          Okay, so next one, let's just duplicate this again.
          
          And I'm going to say now age is going to be greater than 20.
          
          So the greater than sign.
          
          Is that right, Chevron.
          
          And in our case, this is going to be true because age is 25, which is over 20.
          
          So let's save it and we get true.
          
          Let me duplicate this and change this to less than.
          
          And in this case, we're going to get false because age is not less than 20 because it's 25.
          
          Okay.
          
          All right.
          
          So just a couple more.
          
          The next one is going to be less than or equal to and I'm going to change this to 25.
          
          So when we add an equal sign after the Chevron, no matter whether it's greater than or less than,
          
          then this turns it into less than or equal to 25.
          
          Now, this is going to be true because it is 25.
          
          It's not less than 25, but this says less than or equal to.
          
          So that should be true.
          
          And we get true over here.
          
          Okay, one more.
          
          Let's just do the opposite of this.
          
          We're going to say greater than or equal to 25 and save that.
          
          And this statement is true as well.
          
          Cool.
          
          Okay, so there are loads of different comparison operators we can use right here for comparing numbers
          
          and we're going to do that quite frequently later on.
          
          And they all return Booleans Now I'm going to do the same kind of thing, but this time I'm going to
          
          do it with a string.
          
          So I'm going to create a new variable called name and set it equal to Sean, obviously.
          
          And then I'm going to come down here and say console dot log, and we're going to do a very similar
          
          thing.
          
          I'm going to say that name is equal to remember double equals.
          
          Sean.
          
          Now, is that the case?
          
          Well, yeah, this is Sean.
          
          So this statement right here, this should be true.
          
          So I'm going to save it.
          
          And we see true.
          
          Okay, let's do a few more examples.
          
          We'll say name is equal to Sean with a capital S.
          
          Now, what do you think?
          
          Well, this string is not equal to this, is it?
          
          Even though it's the same word.
          
          We have a capital letter here.
          
          And those two things are different in JavaScript.
          
          So if I save it now, we should see false.
          
          Okay, okay, let's do another example.
          
          I'm going to say name is now greater than Crystal.
          
          Now, how does this work with strings?
          
          Well, first of all, if we save it and preview, we can see that this is true.
          
          So it's saying that Sean is greater than Krystal.
          
          And that's the case because the first letter right here's comes later in the alphabet than C.
          
          Now, when that's the case, it's greater than it.
          
          So later letters in the alphabet are greater than earlier letters in the alphabet.
          
          All right.
          
          So what if we added some kind of capital letter to the mix?
          
          I'm going to change this to Sean, but we're still doing greater than now.
          
          Is this Sean going to be greater than this, Sean?
          
          Well, let's save it and find out this is true.
          
          So again, when we have a lowercase letter that is greater than an uppercase letter.
          
          Now that might seem counterintuitive at first, but that's the case in JavaScript.
          
          Lowercase letters are greater than uppercase letters.
          
          Okay, so one more example I'm going to say, is Sean greater than Krystal with a capital C and I'm
          
          going to save it and preview it and true again.
          
          So not only is the small case s greater than its counterpart, the big case s it's also greater than
          
          any uppercase letter.
          
          So all of these kinds of comparisons are going to be really useful to us later on when we start to check
          
          if certain conditions are true or false and then execute some code depending on the result of a comparison.
          
          So, for example, is a user logged in?
          
          If that's true, then I'm going to execute some code to show a user dashboard in the browser.
          
          If it's not, then I won't.
          
          Now, so far, when we've compared two things together to see if they're equal, we've used double equals
          
          right here and that is what's known as abstract equality or loose equality, which means that a values
          
          type is not considered when we perform the comparison.
          
          And we're going to talk about that more in the next video and how we can use a stricter and better type
          
          of comparison for things like this.