Now one thing about variables that are important to point out is that in JavaScript variables are dynamically typed. In some programming languages, a variable when it is established, you need to specify what type of type it will contain, for example, a variable a lot, this variable always contain a string. Well, that's not true with JavaScript since it's dynamically typed. So for example, dog name is already variable we've created and it contains rover. Well, we could change that to a number. Notice the syntax error it gave me It's because I did not enter the the assignment operator.
So now dog name is equal to five instead of the string. So that's an example of dynamic typing in JavaScript. One other thing I want to show you with string with strings values. And to show you this, I want to set dog name back to its original value. Now dog name contains a string, because it is a string. And JavaScript knows that as a string, we have access to some other things we can do with that one of those is which one of those is a length property?
And when I answer that it comes back as four meaning there are four characters in that string. So certain value types have additional methods which you can perform on them. string as an example of that. There are more than just length but length gives you an initial idea of what's possible. Now finally, let's talk about valid names for variables. Some terms cannot be used for variable names.
They are reserved keywords for JavaScript var is one of those so I could not do var var equals 10. If I try to do that, it gives me an unexpected token var. That token cannot be used in the place where I used it in that statement. Because it is it is illegal as a variable name, because it is a reserved keyword. There are other reserved keywords in JavaScript as well. They're they're mainly things that are used in a language for example, an if statement we use an if, so I cannot use if, as the name of a variable either.
Variables are a central part to anything you do in any programming language. One last concept I want to mention about variables is when you declare a variable Make sure you use the var keyword, it is possible to declare a variable without the var keyword as I've done here. That works. That's possible to do. However, I recommend that you get in a habit of always using the var keyword when you're declaring a variable. One final concept that is important to mention is that variables can contain any value.
Mainly we've been looking at strings and numbers, but variables are not limited to just strings and numbers. I can also enter Boolean into a variable. We can enter undefined and null, which we'll talk about in a subsequent movie. We can also enter objects into variables, any type of object in JavaScript I mentioned that arrays, functions. objects, those are all objects. Those can all be stored in a variable as well.
So keep that in mind that you can store any value in a variable. Alright, let's move on to the next topic.