Loading
Current section: 2. Variables 4 exercises
lesson

Intro to Variables

Loading lesson

Transcript

00:00 Sweet. Now it's time to talk about variables and immutability in TypeScript and JavaScript. I'm gonna be using those terms really interchangeably, if you haven't already noticed. So variables are really important in pretty much every program. There are ways to get around them, sort of, but that's definitely, something that you do for sport, not for practice.

00:24 So, yeah, it's important for you to be able to create a variable that you can then reference elsewhere in your program. And this is the basic idea right here. You have this syntax, let or const, and then a space, and then the name of the variable, and then an equal sign, and, then the value. There are a couple of interesting nuances between let and const. One thing that we're not going to cover in this exercise but I thought I'd just mention here is that because of the nature of let, you don't actually have to assign it to anything.

00:58 You could assign it later, count equals 10, and that works just fine. You cannot do the same for, name because, const means that it's assigned and it will never change. You'll learn more about that in this exercise. So, the other thing to consider is, I typically use const by default, and I'll we'll talk about that. I I think you should use let when you know that you need to reassign something.

01:25 Here are a couple other examples. This is a for loop. Oh, preview. You can look at that. We'll see that a little bit later.

01:31 And then we'll also talk about reassignment versus mutation. There's an, an important distinction between that. So this is gonna be an exciting exercise. We also, in this exercise, are going to be exporting for the first time. We do that for the tests as well as for this display right here, because not everything do we want to necessarily console dot log.

01:52 And so, this is something we're going to explore way later when we get to more advanced topics. And so I'm just gonna need you to trust me on this one. Just follow my lead, and and we'll give you the code that you need to. Just uncomment, for this to work so that the tests can verify your work and you can get that output right here. But, there are a couple of ways that you can export things.

02:14 Our typical way that we're gonna do it is like this. So at the bottom of each file, you're gonna find something that looks like this. On my keyboard, I say command and then the comment slash, the back, forward slash, and, that is going to toggle whether that line is commented. So I just do that and it's, nice and quick. So with that, I think that you're ready to tackle this module.

02:35 Have a really good time with it.