Hello, in this JavaScript video, I am going to cover variable so what is a variable variables are really really cool. They allow you to store some piece of data. You know that's it really we've already used it didn't explain too much. So the var keyword just in short for variable, then you need to name your variable. And you can pretty much name it whatever you want. There are certain conditions for naming your variables you can't you know, starting with a number.
You can't use a reserved keyword for example, so you know you can't name evolve, because law is reserved for indicating native variable so reserved keywords are unavailable, then you put equals and then you assign some value. And then you can use it anywhere you can reassign the value as well. So if I just get rid of this, and if I just say hello, we'll see we're not using the var keyword anymore. Many more. That's because we've already declared it. And if if I assign 10 now, grab this, put it here, save it.
Go back, reload and see save 10 Okay, so we t dawn, cool. There is a nother variable that I want to cover or another sort of, I should say, in the new ESX. There is a new sort of format or variable and that is called a left and left is really, really useful. So let's, you know, no pun intended. Let's have a go at that right now. So, if you just put the keyword left, and we can name it something for let's call it Hello, and assign a value of five Don't log on a fly print out Hello, say we fresh a princess flies.
So what's the main difference in one, you cannot just declare it like this where are the very boy you can, it does not like this at all. So your trial resolvable, recommend not doing it. The other main differences is to do with block scope. So look at this. So imagine if I was to declare this inside this block and this could be attached to a function and loop which will cover or just on its own. And let me show you what we're doing with this one.
Save that refresh, and see see uncaught reference Hello is not defined. So with the standard variable, it doesn't actually have block scope, which most variables in most languages do. So if you're coming from another language, and you want to, you know, reduce the scope of your variable, which is a common, you know requirement, then you want to use net. So a lot of time in your applications, you will generally use net over bar. So that's how you create a variable. Just one other thing to note.
In JavaScript, you just specify the keyword box. In some other languages, you have to specify the data type. So in this case, this is a whole number, also referred to as an integer or a decimal is referred to add the float, a string, you know will be a string and character would be a char, you can assign whatever you want to your variable. So if I change this to Hello, world, save that refresh. And it is a Hello World, even though this is a string, and initially it was a number. More specifically an integer.
JavaScript is variable Loose light that you can assign, you know, a variable in one location or one datatype then in another location later on, assign a number variable or another piece of data or a different ID so and you still work so that's just something to bear in mind if you're coming from a another language. And you know, pretty much all data types are supported. Thanks for watching. If you have any questions, feel free to pop me a message and as usual, I will help you and see you in the next video.