WEBVTT

00:01.300 --> 00:06.730
It's time to talk about one of the most fundamental aspects in JavaScript, that is variables and data

00:06.730 --> 00:10.930
types, they are a little bit different from the standard programming languages.

00:10.930 --> 00:16.840
And so I'm going to explain what variables are and what kind of data types JavaScript accepts in details

00:16.840 --> 00:17.680
step by step.

00:18.640 --> 00:20.280
So what is a variable?

00:20.620 --> 00:26.800
It's helpful to think of variables as containers, that whole information which we can use for multiple

00:26.800 --> 00:29.230
times and we can change it dynamically as well.

00:30.250 --> 00:30.730
All right.

00:31.660 --> 00:34.960
In order to declare variables, we need to write var keyword.

00:35.830 --> 00:41.500
This was the engine that it needs to reserve some memory in which to store your data later.

00:42.340 --> 00:49.090
So again, when we declare the variable JavaScript engine understands that it has to create memory space

00:49.090 --> 00:50.720
in which you can store the data.

00:51.640 --> 00:54.790
Actually, this stuff is about how JavaScript works behind the scenes.

00:55.210 --> 00:59.230
So it's the topic of another section and we will definitely discuss it deeper.

01:00.640 --> 01:04.300
Okay, after that, you should set the name to the variable.

01:05.200 --> 01:11.920
Many other programming languages which are called strongly typed languages like Java or C Sharp require

01:11.920 --> 01:16.780
you to declare not only the variable, but also the type of data that will be stored.

01:17.650 --> 01:24.040
However, JavaScript is a weekly typed language and you don't need to limit yourself to what type of

01:24.040 --> 01:25.720
data the variable can hold.

01:26.470 --> 01:32.710
It means that JavaScript engine understands itself what type of data you are storing in the variable.

01:33.740 --> 01:41.120
In this case, verbal person is not assigned by the value, it's just declared we can use a shorthand

01:41.120 --> 01:44.680
method for declaring the multiple variables in one statement.

01:45.110 --> 01:51.920
We just need to write var keyword only once, followed by names of the variables and separated them

01:51.920 --> 01:56.730
by commas that at the end of the statement we have to place semicolon.

01:57.380 --> 02:00.020
So right here, for example, first name.

02:02.180 --> 02:11.000
Last name and age in the real world, this and method is very popular and commonly used in previous

02:11.000 --> 02:15.830
video, you have already seen how to assign a value to the variable for doing that.

02:15.830 --> 02:21.950
We just need to use equal sign, which is known as assignment operator, and it doesn't mean equality

02:21.950 --> 02:22.730
as it's in math.

02:24.170 --> 02:27.090
In this case, the variable person has the value.

02:27.110 --> 02:30.610
Instructor, let's plug it in, console, right.

02:30.620 --> 02:32.270
Console the clock, Pursell.

02:36.560 --> 02:43.790
So you think the value of person variable is structured in the same way we can also use a shortened

02:43.790 --> 02:46.100
method for assigning values like this?

02:46.640 --> 02:59.270
Right, the value for first name as John, that last name as dough and age 27, in order to organize

02:59.270 --> 03:04.790
our code nicely and to make the code easier to read, we can separate them like this way.

03:06.620 --> 03:12.590
And you may have got the question about those white spaces, but I can tell you that JavaScript engine

03:12.590 --> 03:17.060
counts them as one whitespace, so that doesn't cause any errors.

03:17.600 --> 03:22.940
As we said, we can change the values of variables dynamically to understand, well, what it means.

03:22.970 --> 03:27.170
Let's assign to person different value, like, for example, teacher.

03:29.410 --> 03:33.940
And log it in council right again, cancel that log for some.

03:37.790 --> 03:42.210
So you can see that it has changed its value from instructor into teacher.

03:42.830 --> 03:49.610
And this fact also proves that JavaScript engine rates the code line by line from top to down.

03:51.140 --> 03:56.300
All right, the council is the great seal because we can work here without logging every time from the

03:56.300 --> 04:00.950
editor, we can just type here the name of the variables like first name.

04:02.100 --> 04:09.310
That press the enter and you see that he will have value, John, in the same way we can get values

04:09.330 --> 04:14.370
for other variables for last time and also for age.

04:15.240 --> 04:15.750
All right.

04:17.230 --> 04:22.350
You remember from the previous video where we were talking about Syntex parser and writing the valid

04:22.350 --> 04:22.680
code.

04:23.370 --> 04:26.100
So we need to protect some rules when we deal with variables.

04:27.240 --> 04:31.410
If you take a look on the screen, you will see on the left side the valid variable names.

04:32.280 --> 04:38.210
We are allowed to start variable names with a letter or underscore and dollar sign.

04:38.700 --> 04:43.770
And also we can use numbers in names, but we are not allowed to start the names with them.

04:45.070 --> 04:50.860
The first case is commonly used when the name includes two or more words ever, next word starts with

04:50.860 --> 04:53.980
a capital letter and it's called Camil Case Method.

04:55.380 --> 05:01.350
As for the examples on the right side, you're not allowed to use that we cannot use the space inside

05:01.350 --> 05:08.430
the name, also the minus sign because it means subtraction in JavaScript and is used in mathematical

05:08.430 --> 05:09.120
operations.

05:09.960 --> 05:16.440
We're not able to start variable names with signs except underscore and dollar sign and also with numbers.

05:18.110 --> 05:24.660
OK, in this lecture we have talked about variables, how to declare them, how to assign the values

05:24.660 --> 05:26.230
and how to choose the valid names.

05:26.790 --> 05:27.730
Let's stop here.

05:28.170 --> 05:32.190
See you in the next video where you will learn about data types in JavaScript.
