Understanding Basic Types

Transcript

English (Auto-generated)

podcast studio anyway, okay now here we go, okay, come back. Um so we're talking about the you know the basic types of the um the typescript. So you know the the the typescript is the super set of javascript. So ultimately whatever we are doing in the in the javascript we're doing in the typescript. So here we go. First of all, we need to write something like, you know, um let's just make a variable and I'm going to choose the LET because I'm I'm choosing the ES six method. Actually at some point we may be doing the ES six sometimes some at some point we would be doing the S. Nine whatever anyway because you know this this is all the javascript. So let I'm creating a variable and I'm writing str So in the javascript we would say hello world to create um a simple str But because it's typescript, so you would go with this method string, you need to add this string. I think that is super simple and understandable by itself. Similarly, I'm going to go with the next next run. I'm writing Let again and I'm writing S. T. R. Sorry, I'm not going to go with the str Okay, another type is the number. So I'm writing number one or just numb and to declare the type, you need to write the number and equal to and here I am writing like six or and I'm going to the next line and I'm writing Let and here we are writing once when we just wrote the let okay um the true or false. So we can call it the bull, this is another variable. So the type has to be the bully and that is understandable. Now the value of this variable can be you know the truth or the false. I mean it can be true or false both. That is simple. I mean you know anyway these are the basic types in the in the javascript, we know that but maybe you want a dynamic variable two. This is one of the interesting perks that you know you can choose to ways, maybe you can create a variable like you just call it var one or yeah we are one and then you just simply write something like hello world or anything. Um but there is one more way just make it any. So now you can write anything. I'm gonna I'm gonna write some some kind of you know the the string here. So I'm writing hey this is and this is a string now. That's awesome. Okay now let's just go down and I'm gonna I'm gonna print it somewhere, I'm writing it on the console console dot log. And here I'm just simply printing you know S. P. R. For now and I'm saving it. I'm not going to go to the browser, I just want the results in the you know in the javascript because the results are obvious. I'm gonna compile it into the javascript. So ultimately we that would be the result for us. So you absolutely need to know the basic javascript if you're doing the typescript thing. So this is why I'm expecting you that you you do not need the result and if you want the result in the browser you can have the and so anyway, I'm writing TSC, I do not need to mention the index anymore because we have applied DTs conflicts. So just press the enter key and it's going to process everything and it's gonna give us the new file somewhere in this folder. We got it just click on the next dot Js and you got it here. Use this trick because you know, we just programmed it this way. So in the T. S. Conflict. The U. Um here it is. If I go down, you know the the common J. S V. D. W. But um district True. That is already applied anyway. And then you can see that everything is let it is not war because we are using the ES seven by default in the T. S. Conflict. But you can go with the S. Nine or whatever I mean, you know, so um that's understandable. We just cannot see the strings and the types. But we just started that up and also this train the printed discreetly in the console. So we are logging the data and you know that this is a working example of the uh the simple javascript file even you didn't put the, you know the ending semi colons but they're also here by default so that's awesome. Okay, now the point is um I go down and uh I mean um um I'm just just simply going down and I'm just calling the str again and changing the data and I'm writing here something like I do not even mention the type again because the variable is already declared and it has its own type, which is a string. So I'm not gonna I simply cannot assign a new type to this string, this variable. So here I'm gonna write, you know some modification modification. Okay, that would work and how to know if that would work if I simply go there and I write TSC and I just press the ps I mean I just press the enter key and I'm gonna see that here um Right here you can see that the modification that totally works but Maybe I want something different and I want it like, you know, I won nine. Okay, now that is the problem. The type number is not assign able to type screening but the point is if that would work and that would convert it into the javascript or No, so let's just see, I just pressed the key. Okay here, you can see that first read this thing and if I just go above your you can see that you got the error. Found one error. You can see that the error is also mentioned. Okay, that's fine that we are getting the error here but now we need to go to the next dot Js file. It is here. I mean why after the error? That that is here because according to javascript uh this thing, what we did here according to javascript it is possible but in typescript that is not possible. So at least it gives you the error. So you know that something is wrong and you need to fix that. So anyway, I mean it gives the error. So I'm I'm just simply deleting that but I'm writing here war one okay the var one is any so it was a string here. Any means. I mean you know we're not assigning any specific type here but it can be strained. It can be bullied and it can be anything earlier. We we we we put some string with the any type but now I'm making it, you know, I'm writing here like you know false. Okay I'm adding a new data type with it which is false. I mean the bullying so go back here first I'm clearing but a lot of the things happened and I'm writing PSC again and now I'm gonna try on the okay it is done. I'm gonna go to the extra Js okay you can see that there is no where there is nowhere and it was the earlier the war one was a string in a war one is uh the bullion in the in in the javascript that is totally fine. But in the tears the typescript that just simply I mean that totally works too because the any can it is the way to write the dynamic data type. But again if you're writing any so you you also have the option to put nothing. I mean you just can go with this way but I mean if you write any this actually defines that you're writing something in the javascript. This is why defining the type is preferred when you're going with the typescript and absolutely it's much much more regrettable because you know now here the same thing it is but it is readable and now you can understand it. The basic difference you can see that you know you you see that there is a data type false and there is a data type you know actually the bullying type and the string type. But you can see that you defined it as as any. So there must be something and this is why you change the type. Otherwise you may be here, you may be asking yourself that you know it is war one and that is war one and this one has the data type as different and this one has a different data types. I think that that makes things a lot much understandable. Okay so these are the basic data types we'll be going to something more till then stay tuned and watch keep watching our other castes.
78 Views 0 Likes 0 Comments

Understanding Basic Types

Comment
Leave a comment (supports markdown format)