Transcript from the "Template Strings" Lesson
>> Brian Holt: So we just did the sentence here. Hello plus first name, plus last name. This is quite burdensome, right to actually have to go and concatenate all the spaces together. It'd be better if there was a better way to do this, right? There is, there's a better way to do this.
>> Speaker 2: [LAUGH]
[00:00:33] Not the tilde, right, that's what happens when you hit shift that. It's just that without shift, you get little backticks here, right. Now I can say hello. And then there's this curious thing you can do with dollar sign, curly brace. So curly braces are there next above the square braces, you have to hit Shift one which is next to p.
Again, on the American keyboard, and now I can put hello first name.
>> Brian Holt: So, we'll just start with that for just now and then we'll get to the other part of it.
[00:01:26] So whatever the value of this inside of here is going to be outputted into that string, right. So if I say this refresh, now it says hello Brian. So this is just an easier way for us to make these big strings out of other strings work a little bit easier, right, rather than having to do plus this, plus space, plus that, right.
You can just do the dollar sign curly brace. And they're just relying on that being so unique that you would never accidentally put that into your strings, right? Even if you do, you can actually do a backslash right there and then it'll just,
>> Brian Holt: Right now if I go in here those say, hello first name, literally, right?
>> Brian Holt: So, now I can put a space in here, dollar sign curly brace last name,
>> Brian Holt: How are you? Let's make this a little bit bigger over here. So you can see here the, it's almost more like writing normal English. And here, again you can see hello Brian Holt, how are you?
And this is nice cuz I can come up here and say, like I can put my wife's name in there, Niki Holt. It says, hello Niki Holt, how are you? She'll be mortified to know that I was talking about her. No one tell her, please. [LAUGH]
>> Brian Holt: Questions about that?
>> Speaker 3: In this case, where does this space come from?
>> Brian Holt: So the space between Niki Holt, is that what you're asking?
>> Speaker 3: Yeah.
>> Brian Holt: Good question. Notice here that I literally just put a space here.
>> Speaker 3: Okay, so that's working?
>> Brian Holt: Yeah, so if I delete that, notice that NikiHolt becomes one word. Does that answer your question?
>> Speaker 3: Yeah.
>> Brian Holt: Cool.
Is it updated regularly? How often do you have to go and learn these new tags and stuff?
>> Brian Holt: We're talking in too much of a history lesson, it used to happen very infrequently, and now it happens every year.
>> Speaker 4: Okay.
[00:04:06] So, ES2015 or ES6 as it was previously called, which came out in 2015, had a lot of stuff in it. And now we get two or three features a year. So, this was obviously possible before, doing the old way that I showed you, right? This just makes it a ton easier to do it.
Very infrequently do we get new paradigms. The only one I can really think of that was totally new was generators. Everything else has been which we're not talking about generators today. That's above my pay grade. Does that answer your question?
>> Speaker 4: Yes, I do.
>> Brian Holt: Cool, anyone else?
Good questions, yeah.
>> Speaker 5: So for part of the sentence I put I am, and then dollar sign without a space, and bracket and then my age is one of the variables I did, and it does have a space between the M and my age. So, does the dollar sign, etc, automatically put in the space?
>> Brian Holt: Did you put a space between the two things?
>> Speaker 5: No, so if you put some text in between, those two, yeah, that. Is there any space that gets?
>> Brian Holt: Notice that it's all shoved together there.
>> Brian Holt: It's not going to automatically insert anything for you. It's gonna do exactly what you tell it to do.
[00:05:35] One more thing about template strings. So if I wanna put a hard return in here. So if I hit enter a couple times, this is actually valid with templet strings. So now if I save this and run it again, notice that there's a lot of space in here.
You can't do this with single quotes or double quotes. So if I change this from a backtick to a,
>> Brian Holt: This is not valid because it doesn't know what to do about that. So, with backticks, you can also put hard returns in there.
>> Brian Holt: Great,