It's time to talk about one of the most fundamental aspects in JavaScript, that is variables and data
types, they are a little bit different from the standard programming languages.
And so I'm going to explain what variables are and what kind of data types JavaScript accepts in details
step by step.
So what is a variable?
It's helpful to think of variables as containers, that whole information which we can use for multiple
times and we can change it dynamically as well.
All right.
In order to declare variables, we need to write var keyword.
This was the engine that it needs to reserve some memory in which to store your data later.
So again, when we declare the variable JavaScript engine understands that it has to create memory space
in which you can store the data.
Actually, this stuff is about how JavaScript works behind the scenes.
So it's the topic of another section and we will definitely discuss it deeper.
Okay, after that, you should set the name to the variable.
Many other programming languages which are called strongly typed languages like Java or C Sharp require
you to declare not only the variable, but also the type of data that will be stored.
However, JavaScript is a weekly typed language and you don't need to limit yourself to what type of
data the variable can hold.
It means that JavaScript engine understands itself what type of data you are storing in the variable.
In this case, verbal person is not assigned by the value, it's just declared we can use a shorthand
method for declaring the multiple variables in one statement.
We just need to write var keyword only once, followed by names of the variables and separated them
by commas that at the end of the statement we have to place semicolon.
So right here, for example, first name.
Last name and age in the real world, this and method is very popular and commonly used in previous
video, you have already seen how to assign a value to the variable for doing that.
We just need to use equal sign, which is known as assignment operator, and it doesn't mean equality
as it's in math.
In this case, the variable person has the value.
Instructor, let's plug it in, console, right.
Console the clock, Pursell.
So you think the value of person variable is structured in the same way we can also use a shortened
method for assigning values like this?
Right, the value for first name as John, that last name as dough and age 27, in order to organize
our code nicely and to make the code easier to read, we can separate them like this way.
And you may have got the question about those white spaces, but I can tell you that JavaScript engine
counts them as one whitespace, so that doesn't cause any errors.
As we said, we can change the values of variables dynamically to understand, well, what it means.
Let's assign to person different value, like, for example, teacher.
And log it in council right again, cancel that log for some.
So you can see that it has changed its value from instructor into teacher.
And this fact also proves that JavaScript engine rates the code line by line from top to down.
All right, the council is the great seal because we can work here without logging every time from the
editor, we can just type here the name of the variables like first name.
That press the enter and you see that he will have value, John, in the same way we can get values
for other variables for last time and also for age.
All right.
You remember from the previous video where we were talking about Syntex parser and writing the valid
code.
So we need to protect some rules when we deal with variables.
If you take a look on the screen, you will see on the left side the valid variable names.
We are allowed to start variable names with a letter or underscore and dollar sign.
And also we can use numbers in names, but we are not allowed to start the names with them.
The first case is commonly used when the name includes two or more words ever, next word starts with
a capital letter and it's called Camil Case Method.
As for the examples on the right side, you're not allowed to use that we cannot use the space inside
the name, also the minus sign because it means subtraction in JavaScript and is used in mathematical
operations.
We're not able to start variable names with signs except underscore and dollar sign and also with numbers.
OK, in this lecture we have talked about variables, how to declare them, how to assign the values
and how to choose the valid names.
Let's stop here.
See you in the next video where you will learn about data types in JavaScript.