Stop Low Resolution Warning Sign

Transcript

Transcript of the tutorial. TOP


          
        
          So then the first data type I want to explore in more depth are strings.

          So we use strings to store letters, numbers or other characters, and we could use them to store something
          
          like a name or an email address or something like that.
          
          So what I'll do is just log to the console a simple string.
          
          So I'm going to say console, dot log.
          
          And remember, we store strings in either single quotes or double quotes.
          
          Now they behave the same way.
          
          It doesn't matter which one you use, but if you open with a single quote, you close it with a single
          
          quote.
          
          If you open with a double, you close it with a double.
          
          I generally use single quotes for strings, but sometimes you might see me use double quotes if I need
          
          to.
          
          So I'm just going to say hello world and put my semicolon on and save this.
          
          And we should see this logged to the console.
          
          Now we don't see the quotes right here, but that doesn't matter.
          
          Over here we add quotes to make a string.
          
          Okay, so then we can also store strings inside variables.
          
          So I could say let email equal to some kind of string.
          
          For example, Mario at the net ninja.co.uk and now that is stored in this email variable.
          
          So if I wanted to, I could log this to the console by saying console, dot log and then email.
          
          So if I save this, we should see both of those things now logged to the console.
          
          Cool.
          
          Okay then.
          
          So imagine we had two strings and we wanted to join them together.
          
          Well, that is called concatenation.
          
          So concatenation is just a fancy word for joining things together.
          
          So if we had two variables, for example, let first name equal to Brandon and then we'll say let lastname
          
          equal to Sanderson.
          
          What I want to do is join these two different strings together.
          
          Now I can say let full name equal to first name plus last name.
          
          So this is string concatenation.
          
          We use a plus sign to concatenate one string to another string.
          
          In other words, to join one string to another string.
          
          So if I say console, dot log full name.
          
          Now then we should see this in the console.
          
          Now if we take a look over here, we can see Brandon Sanderson, but there's no space in between the
          
          two names.
          
          So what we could do is concatenate after the first name, a string, which is just a space.
          
          Then we can catenate the last name.
          
          So we're concatenating three different things here.
          
          The first name, then a string, which is just a space, then the last name.
          
          So now if we save this, we can see Brandon Sanderson with a space in between.
          
          Okay, so we can do this kind of thing.
          
          So we can also extract a single character from a string that we have stored.
          
          For example, this one by using square bracket notation.
          
          So I'll show you what that means.
          
          I'm just going to say console dot log, first of all, then we're going to take the full name and say,
          
          for example, I want the first letter in that name.
          
          Then I can use square brackets and I pass in zero.
          
          Now we pass in zero because JavaScript is a zero based language, meaning it counts from zero up rather
          
          than one up.
          
          So in JavaScript this is position zero, the first letter, the second one is position one, then two,
          
          then three, so forth.
          
          Okay, so zero actually gets me the first character.
          
          So this is why we use square brackets after a string to get a single character in a particular position.
          
          So this should get me B and we should see that in the console.
          
          Cool.
          
          Now, if I wanted to change this to another, I could say two and that should get me the A because.
          
          012.
          
          So if I save it preview we see a okay, so that's how we get a single character using this square bracket
          
          notation on a string.
          
          Now a string also has methods and properties.
          
          Now one such property is the string length.
          
          So we could say something like this console dot log and find the length of the string.
          
          That is how many characters are inside the string by saying full name dot length.
          
          And that gets us the length of this string right here.
          
          So if I save, we see 17 and if we were to count the characters, which are not going to do, we would
          
          find that the 17 characters and this right here, this is one of them space.
          
          Okay, so that's the length property.
          
          And finally, strings have several different functions associated with them.
          
          Now these functions are called methods, and there is a technical difference between functions and methods,
          
          but you're going to hear them used interchangeably.
          
          So basically a function is a snippet of code which performs some kind of specific task.
          
          A method is just a function that's associated with a particular object or data type, and we're going
          
          to discuss the technical differences later on.
          
          But the two words essentially mean the same thing.
          
          So if I say method or function, they both mean that we're performing some kind of function that does
          
          something.
          
          And a string has several methods, several functions that can do things.
          
          Okay?
          
          So for example, we have a method called to uppercase.
          
          And what that does is take the string and it turns it so that all the letters are uppercase.
          
          So I could say something like console dot log, we do the string, we want to use the method on.
          
          So full name.
          
          Then we say dot and we say to uppercase.
          
          So this is the method name.
          
          So when we have properties we say dot and then the property name.
          
          But this isn't a function, this is just a property of the string.
          
          It's not actually performing some kind of snippet of code to do something.
          
          It's just finding out a property of the string.
          
          This down here to uppercase.
          
          This is a method, a function which actually does something.
          
          It takes our full name and it turns it to uppercase.
          
          So because this is a method, what we do is add brackets or parentheses on the end of it.
          
          So whenever you see something like this dot and then some kind of name and then parentheses, it means
          
          that this is a method of whatever we're using it on.
          
          Okay?
          
          In this case it's a string method.
          
          So if we save this now, we're going to see that it's going to take our full name, our string, and
          
          it's going to turn it to uppercase, and then we're going to log that to the console so we can see now
          
          Brandon Sanderson in all uppercase.
          
          Okay.
          
          Now there are other methods as well.
          
          I'm going to show you another.
          
          And this time what I want to do is store a result inside a variable.
          
          So I'll say let result equal to full name, dot to lowercase.
          
          Okay.
          
          Now what this does is the opposite.
          
          It takes the full name and it's going to turn it to lowercase.
          
          But instead of logging this to the console like we did up here, what we're doing is actually taking
          
          the value that this gives back to us and we're storing it in a value called result variable.
          
          Okay, Then what we could do is use this later on.
          
          For now, we are just going to log this to the console console dot log.
          
          I just wanted to show you that we can store the values that are returned to us right here so I can say
          
          result like so save it and we can see this in the console.
          
          Now it's all lowercase before up here.
          
          Normally it started with a capital both names, but now it's all lowercase.
          
          Now I want to make one thing clear.
          
          These methods right here, they don't actually alter the variables themselves.
          
          The original variable, this full name.
          
          So if I was to log out the full name as well, we're going to see that it's still going to be Brandon
          
          Sanderson like this capitalized.
          
          So if I save it, preview it in a browser, we can see that we get this one right here.
          
          Brandon Sanderson with just a capital letter at the start of each name.
          
          So these methods, they do not actually alter the original value that we use them on.
          
          Now, some methods do alter the original value and some methods don't.
          
          So these are just cases where they don't alter the original value.
          
          Now sometimes we can use methods which expect us to give them a certain value.
          
          So for example, I'm going to use another method down here, but before I do that, I'm going to say
          
          let index equal to the email.
          
          I remember that email value was this thing up here.
          
          We said email is equal to Mario at the net ninja.co.uk.
          
          So I'm creating a variable called index.
          
          I'm setting it equal to email dot index of.
          
          So this is a method and it's going to find the index of a certain character inside this string.
          
          So by index I mean the position.
          
          So what I want to do is tell it to find the index of the at symbol, okay, So I can pass in as a string
          
          in quotes the at symbol to this method.
          
          Now this.
          
          Sitting right here.
          
          This is called an argument, but you might also hear them being called parameters, including when I
          
          talk about them, because they're easy words to get mixed up.
          
          But technically speaking, when we pass a value into a method like this, this is an argument.
          
          Okay?
          
          So what that's going to do is find the index of this inside that string email and it's going to return
          
          that value to us, which we're then storing inside this variable.
          
          So now if I say console, dot log and then the index like so I'm going to save it, come over here and
          
          we can see five.
          
          Now if we count them zero for the first position, then one, then two, then three, then four, then
          
          five.
          
          Okay, so it gets us that index.
          
          So then the takeaway points here are that strings are a series of letters or numbers.
          
          And by the way, we can add numbers in here.