Hello again, everyone.
So we're going to start a new lesson, and in this lesson, we'll talk about data types in TypeScript.
So actually, I think you're probably familiar with this topic from earlier JavaScript and different
programming languages that you may know already, but in this lesson I want to talk about the intricacies
of typescript.
So basically, when we say the data type of a variable, well, the first things that come to mind will
be values such as string and number and boolean.
So let's see how these values are defined in typescript and how they're used.
So now we first use the let key word to define a variable.
And the name we want to use after, for example, say X here.
And we put in a call in and the type that we want to specify, so we'll use String as our first example.
So then we can give the value just by putting equals or we can define it this way and give the value
later.
Another way to define it could be.
Just like we do here.
We first specified that we will use string data and then we set a value.
It's now the final variable, why using Aulet key word again.
And I give a number as the first value well, actually, by doing this, I indicate that I have defined
a number of variable.
And if I then go and assign a string value to the variable, why here is TypeScript warning me.
It tells us that you have defined variable Y as a number, you cannot give a string value and as you
know, we won't see that warning in JavaScript.
All right, so that's that's why defining this is important here.
So why don't we talk about which variables will use?
All right, so we've already seen that we can use strings and numbers here.
And we can assign a boolean value.
And of course, billions will take a.
Value of true or false?
We can also define a race.
So for this, we can make a few different definitions, we can see them if you want to, because you
know that we can use square brackets in the array definition.
Of course, we can prepare a string, not just as a number, but in a list.
So I want to show you another use.
Now, one type array.
And to find the array type between the greater than in maths and science.
Now, here again, assuming we have prepared a series of numbers, the right number here.
So what if I use a string expression and an array that I define as no in this way?
Of course, it's going to give us a warning here, because we stated that it's a no ray.
But if we don't want to make any definitions here, there won't be any warning, as you can see here.
Cool.
So there's also a tuple type that allows us to define a different data type array.
And TypeScript, you can see how.
All right, so now, while doing the definition, we can specify that the first element in this array
can be a number in the second element can be a string.
And here I use number as the initial value, then a string value.
So at this point, we should pay attention to the element with the index, zero is a number and the
element with the index is a string.
So if we move around here, then we get an error.
So that's why you have to be careful at this point.
All right, so we can refer to any.
As another data type.
So sometimes there may be uncertainty about which data type to use while developing a project.
So at that point, any data type comes to our rescue.
And here we just determined the variable using the let keyword while defining then we can define as
any if we want to or if we don't specify anything here, then we can define different data types later.
Just like we do here.
And as you can see, we've defined this way and received no errors.
But we also know that when we did type assignment.
We could not give any values like this.
So as the next variable type, we can refer to ENUM.
So Inam is a data type that does not have JavaScript, but it comes with TypeScript.
Allows us to number in more meaningful ways, so I'll show you a small example of colors here.
So use this data type Inam and then I wrote Colors and.
I'm typing in a few different colors.
When we are going to use, like, the red color somewhere here.
The value returns to us will be zero by default.
It's now and we define the red variable and call it here, the next value zero.
For the next couple hours, one.
And then the next college to.
As you can see, writing just like this makes it happen.
So if I add another color in between.
Of course, these numbers need to change.
And if we don't want to encounter that kind of situation.
You do the definition this way.
So here we can define the number that we want.
It doesn't have to even be in line.
If I want to, I can set a value like five for this and three for that.
Now, where I use them, I'll see five or three as a result.
Now, if you want to, we can create our JavaScript file and see how this enumeration works.
And as you remember.
We were doing this just by running the TSA code in terminal.
And yep, our jazz file has been created.
And there you can see the infrastructure that we created in our tax file corresponds to the function
and J.S..
And when we look at our other codes, the let key word was replaced with VAR.
So it's basically the same logic, just a few small changes, so I think that's enough for this lesson.
What do you say now?
There are a few more data types that I want to explain, but I don't want to go on too long here.
We're going to talk about them in the next lesson.
I'll see you then.
Good bye for now.