Check out a free preview of the full Complete Intro to Web Development, v2 course:
The "Numbers, Strings, and Booleans" Lesson is part of the full, Complete Intro to Web Development, v2 course featured in this preview video. Here's what you'd learn in this lesson:

Brian introduces strings, which are words or characters stored in a variable, and the merging of different strings together with concatenation. Booleans are a special type of setting a true or false value.

Get Free Access Now

Transcript from the "Numbers, Strings, and Booleans" Lesson

[00:00:00]
>> Marc: So, you wrote your first JavaScript. You wrote your first programming, possibly. Pretty cool. So numbers, strings, and booleans. These are called types. You don't really have to care a whole lot about that but just know that there are multiple different kinds of variables. So whereas before we were dealing with numbers, right, I think this makes sense, that monthlyRent = 500.

[00:00:27] By the way, if you have like 1500, do not put commas between numbers. That doesn't work. Just so you know. Actually, pretty soon you'll be able to put underscores there. That's a new part of JavaScript, people wanted it, I don't care. Anyway, not today. You can't do that today.

[00:00:45] But don't separate numbers, I guess that's what I'm trying to say. So we're going to be dealing with something called strings. So they're called strings because they are a string of characters strung together, think like Cheerios on a string, right. Same thing, this is a bunch of characters put together.

[00:01:07] And they're either between single quotes, double quotes, or back ticks. Back ticks are the ones that are on the same key as the tilde, which is the left of one, right. It looks like that. It's probably really hard to see but that's back tick. So you can also use that instead of double quotes.

[00:01:26] You can put a back tick here as well and that works just fine.
>> Marc: So again this is called a string which is basically like words and character and stuff like that. So now my name is being stored inside of this variable and then I console logged out my name.

[00:01:47] And you see down here, it's logging out the string, Bryan Holt. The word string is really important, it's something that you should remember. It's important across all programming languages, all them column strings, so it's just what you need to know.
>> Marc: Questions about strings so far?
>> Marc: Okay.

[00:02:12]
>> Marc: They're everywhere in programming as you might imagine. We're constantly keeping track of things like address, names of products, cities, anything you can think of, we use strings everywhere. So they are quite important.
>> Marc: We can connect strings together using plus signs. We are basically almost doing like string math.

[00:02:33] So if I have sentence right here with the first name and last name. And I do console.log(sentence). I have hello. Notice that there is a space there. firstname space, because I want a space between my first name and my last name. And it says, How are you? So it says, Hello Brian Holt How are you?

[00:02:53] Right, if we're looking at this?
>> Marc: Right there?
>> Marc: Make sense? That's called string concatenation because we're just connecting strings together to make a larger string. Now, again, you need spaces here. Otherwise, if you look, if I got rid of all of these.
>> Marc: It would mush it all together, right?

[00:03:21] You actually have to tell it, please put spaces here or it does not do it. Cuz the computer does exactly what you tell to do which is both a good and a very terrible thing. So, that's why you need to spaces there as you get the spaces between Hello Brian Holt.

[00:03:37] So, this is the old way of doing this. It's tedious as you can see, you have to put a lot of plus signs in here. It'd be better if we didn't do have that way. So you can do these with what are called template strings. Template strings are brand new, as of 2015 which is quite new for JavaScript.

[00:03:53] By now it's like a 30 year old language. So if I put back ticks, notice this one is using double quotes and I could've just as easily put single quotes here as well. If you put back ticks this is called a template string. So again, that's one of next the one key to left key, the left of the one key on your keyboard.

[00:04:15] Put it back and I say, Hello firstname Lastname, How are you and you get the exactly the same effect. You have this $ sign curly brace. And then you have something inside of here and then end curly brace over here. That's how you basically tell JavaScript to like, hey, I want to a put a variable here.

[00:04:35] So I have my first name being stored here and then I'm putting that out here with hello first name, there's a space here, right? But I could have just as easily put a bunch of spaces there, and you can see that it moves over.
>> Marc: So ${variable}, and you can do that as many times as you want inside of your template stream.

[00:05:04]
>> Marc: Any questions?
>> Marc: So it's very key that you're using back ticks here. I just wanna like emphasize that a couple of times. In order to use the template functionalities, you must be using back ticks.
>> Male: That only works with, that new, with those new features that you're referencing.

[00:05:31]
>> Marc: Which new features?
>> Male: The sentence with template.
>> Marc: Yeah.
>> Male: Okay.
>> Marc: Yeah, so if you wanna use the new features, you have to be using the back ticks. If I put single quotes or double quotes here I would actually literally get that outputted right? Which is probably not what you're going for.

[00:05:49] Now by the same token up here I don't actually have to use double quotes up here. First of all you can use single quotes that works fine and you can even use back ticks up here. And that works as well. The key with back ticks is that if you want to use the template strings, you have to use the back ticks.

[00:06:07] That's the only extra thing.
>> Marc: Okay.
>> Marc: Any questions about back ticks or anything like that?
>> Marc: Yes?
>> Male 2: I think I have kind of a basic question but I just wanna see, so we dealt with numbers and then we brought in variables. And so if you brought numbers into variables, we just lose any ability to do mathematical computations on that because, or is that still possible?

[00:06:42]
>> Marc: That's a great question. So if I start bringing in numbers to my strings and start mixing the two together, what happens? What properties does that have? So actually let me make sure. Down here somewhere. I do have an entire section about talking about this coercion. We will get to the section on coercion here in just a second.

[00:07:09] But you can use numbers inside of strings, right. They're considered just another character. So I could put 5 here, something like that. That works totally fine. But once it's a string, you can't really do math with it. So if I do const five = "5", and notice that this is inside of quotes.

[00:07:31] So now, this is a string 5. If I do console.log five + five, it's not gonna give you ten. You get 55 because it's concatenating the strings together. So that's what you would actually expect. Now, I will talk about how to get around that a bit later.
>> Marc: But yeah that's a great question.

[00:08:00] Any other questions? Please.
>> Male 3: Is there [COUGH] a unique convention for adding notes in JavaScript?
>> Marc: Yep.
>> Male 3: That don't write into the code?
>> Marc: So a thing called comments.
>> Male 3: Use the slash.
>> Marc: Slash slash.
>> Male 3: Slash slash.
>> Marc: There's two ways to it actually. You can also use the same that you did with CSS and do */.

[00:08:27] The difference is // is gonna do it just on one line. So now this is another,
>> Marc: Right? This will execute here but if I do /*, anything until I close it, this is still a comment. Does it makes sense?
>> Male 3: Yes.
>> Marc: Cool, good question.
>> Marc: Other questions?

[00:09:02]
>> Marc: All right.
>> Marc: Booleans, booleans are true or false. I think it's named after Bool? [LAUGH] Who I think was a mathematician. Like if I was doing some sort of like smart home technology and I was just trying to check if he light is on or off, I would represent that as a Boolean.

[00:09:26] And I would say, lightIsOn = true and if the lights were on then I would set it to true and then if they were not on, then const lightIsOn = false. Booleans, Booleans are true and false. You're gonna use them all over the place, Booleans are quite useful, and you just write const lights equals true for true and you do false for false, and that's really all there is to Booleans.

[00:09:55]
>> Marc: Numbers are a type, we've kind of already dealt with them a little bit. Some languages separate numbers into multiple different types. Usually integers and floats but we do not do that in JavaScript. We have one number type and it's called number. [LAUGH] Surprise, so whether it's a whole number like, one, two, three, four, five, 10,000, 50,000, 5,005, whatever it is.

[00:10:23] Or if it's a decimal number, which is what other languages would normally call a float like, 1.2, pi, whatever, those are represented as the same thing in JavaScript. So you do not have to separate those out in your head. That being said, it kind of makes painful because if you're trying to do precise math like very precise math trying to measure very small distances or currencies can also be a problem.

[00:10:52] JavaScript math can be quite inexact to the point that it's quite annoying. [LAUGH] So be careful about doing precise math in JavaScript, you will have problems.
>> Marc: Questions about that? It's kind of high level, I think that's something you kinda just have to experience and then we'll kinda get going and you'll understand that.