WEBVTT

00:01.010 --> 00:07.580
So we have finished considering our helpers, and now it's time to actually start describing updated

00:07.580 --> 00:11.660
and new features of JavaScript, which are represented in its version.

00:12.690 --> 00:19.800
Generally, I would like to note that there was almost nothing in ECMAScript 2015 or ESX version that

00:19.800 --> 00:21.570
could not be done using S5.

00:22.230 --> 00:27.960
So because of that, throughout this section, in most cases we will compare year five and six code

00:27.960 --> 00:28.560
to each other.

00:29.540 --> 00:35.060
The first thing that we're going to discuss is the most popular change in ethics, which is variable

00:35.060 --> 00:38.500
declaration, you already know how to declare variable.

00:38.840 --> 00:40.760
We have done it dozens of times.

00:41.330 --> 00:43.160
For that, we need to use keyword war.

00:44.150 --> 00:45.560
With name and value.

00:49.390 --> 00:49.840
Let's.

00:51.030 --> 00:52.620
Look them in council.

00:56.570 --> 00:58.910
So here we have John and 28.

01:00.210 --> 01:05.880
In year five, we are able to change dynamically values of the variables, for example, if we assign

01:05.880 --> 01:11.820
to name and age variables the other values like Nick and.

01:13.550 --> 01:15.260
29 to age.

01:16.860 --> 01:19.300
Then they will be dynamically changed.

01:20.040 --> 01:25.710
This stuff is different in year six and let's see how it actually works in new version of JavaScript.

01:25.740 --> 01:32.550
There are two types of variable declarations left and cost where we want to update the content of variable

01:32.550 --> 01:33.270
dynamically.

01:33.690 --> 01:39.870
We should use keyword LAT, but if we want to never change the content of the variable, then we have

01:39.870 --> 01:43.220
to use const, which actually stands for constant.

01:44.010 --> 01:47.490
In this case, I'm going to declare any variable with const.

01:48.400 --> 01:52.150
Because you agree that in most cases the name of the person never changes.

01:52.480 --> 01:54.740
As for the age, it's definitely changed.

01:54.790 --> 01:57.020
Therefore, I'm going to declare it with LET.

01:57.730 --> 02:02.890
Actually, this is the main and the only difference between that and declarations.

02:03.850 --> 02:04.300
All right.

02:04.870 --> 02:11.290
Let's reload the page and you see that we have an error and the problem is an assignment to constant

02:11.290 --> 02:11.760
variable.

02:12.370 --> 02:17.760
So as we said, when you assign the value to constants variable, then you can never change it.

02:17.980 --> 02:22.450
It doesn't matter if you write your neck or its initial value, John.

02:23.370 --> 02:25.590
Anyway, we will get an error.

02:26.680 --> 02:29.950
So you cannot use assignment operator.

02:30.400 --> 02:33.970
I mean, equals sign with the same constant variable twice.

02:35.360 --> 02:41.150
OK, as for the constant variable, I would like to note that recently there was a special convention

02:41.150 --> 02:41.840
in JavaScript.

02:42.200 --> 02:48.230
If developers wanted to never change the values of variables for that, they were using capital letters

02:48.230 --> 02:50.060
with variable names like this.

02:53.510 --> 02:54.050
All right.

02:55.180 --> 02:57.280
Let's delete this line of code.

02:58.270 --> 03:07.360
Reload and we have John and 29, so in case of that variable, we do not have any problem with updating

03:07.360 --> 03:08.590
the value of the variable.

03:09.340 --> 03:14.940
At a glance, it seems that that declaration works exactly as VAR Declaration does.

03:15.400 --> 03:20.770
Actually, I can tell you that they work in a similar way, but there are some differences between those

03:20.770 --> 03:21.460
declarations.

03:22.150 --> 03:23.920
All right, let's remove this code.

03:25.230 --> 03:30.960
So as we know, in year five, we can create a variable, for example, person.

03:32.340 --> 03:35.310
And assigned to its value, John Smith.

03:36.960 --> 03:42.810
And then using the same verbal name, we can overwrite new value to old one.

03:45.400 --> 03:48.190
So if we check in councilperson variable.

03:49.250 --> 03:51.080
Of course, we will get to.

03:52.400 --> 03:56.720
Let's see what happens in Essex, change of our keyboards into let.

03:58.930 --> 04:05.460
That revolt and you see that we have an error, which tells us that person has already been declared

04:05.650 --> 04:10.710
so which means that in Essex you are not able to overwrite value of the same variables.

04:11.080 --> 04:16.000
And actually, it's really helpful and great picture because in practice, when you deal with large

04:16.000 --> 04:19.990
code, it will allow us to avoid naming conflicts with variables.

04:21.030 --> 04:27.750
All right, let's talk about another difference between that and Hvar, that's the latest line of code

04:28.260 --> 04:30.660
and change that into VAR.

04:32.320 --> 04:33.730
And running council.

04:34.910 --> 04:36.920
Rite Aid before its declaration.

04:40.560 --> 04:46.350
So you see that we have undefined because of hoisting, and I'm sure that you remember what hoisting

04:46.350 --> 04:49.200
think is if we change over into that.

04:51.070 --> 05:00.130
And as a result, we have an error saying that person is not defined, so JavaScript engine, instead

05:00.130 --> 05:03.360
of undefined directly gave us an error.

05:03.490 --> 05:05.140
And in my opinion, it's better.

05:05.680 --> 05:11.590
Actually, JavaScript engine knows that there exists this variable, but it doesn't allow us to richet.

05:12.130 --> 05:14.860
This is known as temporal, that zone.

05:15.310 --> 05:19.330
It's not actually official term, but most developers use it.

05:20.480 --> 05:24.650
We will get absolutely the same results if we use constant instead of that.

05:28.800 --> 05:35.660
All right, that's the latest Cote's I want to show you one more difference between left and cost.

05:36.000 --> 05:41.910
Many developers actually do not mention it, but I want to refer to it as we remember, when we create

05:41.910 --> 05:47.280
variable on global level, it actually is stored as a property of global window object.

05:47.940 --> 05:51.000
So if we write for a equals the 10.

05:54.320 --> 05:56.060
And then check the window object.

06:00.310 --> 06:03.260
We will find variable as it's property.

06:04.450 --> 06:10.390
Also, if we write we know dot a, then we will get time.

06:11.140 --> 06:14.780
Let's see what happens in case of that and constant change.

06:14.890 --> 06:16.000
Varin into that.

06:17.410 --> 06:20.320
That reload and check again window object.

06:22.710 --> 06:28.920
You see that we cannot find here a also if we write window dot a.

06:30.510 --> 06:32.250
That we will get undefiled.

06:33.450 --> 06:37.050
The exact same happens if we use constant instead of let.

06:42.530 --> 06:47.120
I won't be sold as a property of global we don't object and also.

06:48.180 --> 06:49.350
Window dot a.

06:51.650 --> 06:53.330
Will give us defined.

06:54.290 --> 07:01.430
So in its sixth version, let and cost variables declared on global level are not stored as properties

07:01.430 --> 07:07.580
of global window object, but regardless of that, they act as global variables if they are declared

07:07.580 --> 07:10.350
on global level like it's in case of vah.

07:11.030 --> 07:11.510
All right.

07:11.870 --> 07:15.800
Let's go ahead and talk about the main difference between Vialet and cost.

07:16.640 --> 07:20.180
As we know in is five variables are functions skulked.

07:20.660 --> 07:22.040
Let's recall what it means.

07:22.430 --> 07:27.380
Creates Function A and inside Kurla prices.

07:28.730 --> 07:29.640
A variable be.

07:30.870 --> 07:32.160
With the value, hello.

07:34.400 --> 07:39.200
And then outside of function, run in council, the barrier will be.

07:41.380 --> 07:46.640
If we reload, we will get an error, which tells us speed is not defined.

07:47.620 --> 07:53.380
So in this case, verbal B is a function scope and we cannot access on it from outside function.

07:54.280 --> 07:55.840
The same happens with LET.

07:58.850 --> 08:01.580
And also with constant.

08:03.280 --> 08:05.830
In both cases, we have is not defined.

08:06.810 --> 08:13.040
So let's add cost variables are functions coped as well, but at the same time, they're blocks coalbed

08:13.110 --> 08:18.420
variable declarations and it's the main difference between Vah and Letton constant.

08:18.630 --> 08:20.580
Let's see what this exactly means.

08:20.580 --> 08:23.250
Delete this function and create if statement.

08:24.330 --> 08:27.270
And as a condition, let's just insert here through.

08:29.530 --> 08:33.310
That inside culebras is a variable for steam.

08:34.780 --> 08:36.820
And assigned to it to value John.

08:39.650 --> 08:43.910
Then run it in council from outside if statement.

08:47.590 --> 08:50.240
Revolt, and, of course, it works.

08:50.530 --> 08:51.680
We have John here.

08:52.120 --> 08:53.920
If we change over into that.

08:56.150 --> 08:56.960
That remote.

08:58.510 --> 09:02.710
You see that we have an error saying that first name is not defined.

09:03.930 --> 09:07.320
The same will happen if we use Carlstadt instead of that.

09:11.170 --> 09:17.710
So, as we said, let in constant variables are blocks kept in block, I mean, everything that is surrounded

09:17.710 --> 09:18.960
by color braces.

09:19.360 --> 09:25.600
So if we create outside of if statements variable first name using that declaration.

09:28.490 --> 09:35.920
That we will have Nic in council, regardless of that, those variables have the same names, first

09:35.930 --> 09:38.900
name, they are completely different variables.

09:40.320 --> 09:43.770
If we run inside block first name in Castle.

09:47.710 --> 09:53.020
Then we will get John and Nick, so it means that those are different variables.

09:53.890 --> 09:54.400
All right.

09:55.610 --> 10:01.160
The next thing that I want to show you is that in case of that declaration, we are able to declare

10:01.160 --> 10:05.170
it outside of block and then assign the value inside block.

10:05.600 --> 10:12.470
So if we just get rid of inside, block the let keyboard and also delete this constant dialogue, then

10:12.980 --> 10:16.400
we will get the updated value of variable first name as John.

10:17.750 --> 10:19.340
But in case of constant.

10:21.350 --> 10:26.540
We cannot do that because we cannot we assign to concepts variable, new value.

10:27.650 --> 10:33.980
But in case of consent, there was one exception when we deal with objects, let's change back constantly

10:33.980 --> 10:40.040
to that and create new objects with constant declaration, right person.

10:40.580 --> 10:47.630
And in 30 years, some properties name as Jane and then the age as 18.

10:49.440 --> 10:54.720
Then if statements change the value of age property and make it 19.

10:55.700 --> 10:58.640
And then running castle person object.

11:01.000 --> 11:09.160
You see that the value of property is changed from 18 to 19, so when we use the declaration with objects,

11:09.610 --> 11:13.150
we can manipulate all the values of the properties of that object.

11:14.260 --> 11:14.880
Makes sense.

11:16.610 --> 11:17.060
All right.

11:18.320 --> 11:25.250
Now I'm going to demonstrate what happens when we deal with a loop's, so create simple for loop, right?

11:25.250 --> 11:32.360
Verbal eye equals zero, then as a condition I'm going to write your eye is less than five.

11:33.410 --> 11:35.270
And then the increment I plus plus.

11:36.430 --> 11:39.600
Inside Collaborationists, that's Log-in Castle.

11:40.150 --> 11:40.480
I.

11:42.720 --> 11:50.600
Let's reload and we have numbers from zero to four in case of our declaration, we are able to access

11:50.700 --> 11:52.610
variable from outside of volume.

11:53.040 --> 11:55.770
So if we write, cancel that log, I.

11:58.270 --> 12:00.580
Then we will get five.

12:01.900 --> 12:08.440
If you expected four or something else instead of five, I would like to remind you that after a situation

12:08.950 --> 12:12.850
I is increased to five, condition became false.

12:13.510 --> 12:19.630
So Loopt has stopped execution and that's why the value of variable AI has been maintained as five.

12:21.350 --> 12:23.920
All right, let's change of our intellect.

12:26.400 --> 12:27.000
Revolt.

12:28.070 --> 12:34.400
And you see that at first we have numbers from zero to four, that's because of first class Deathlok,

12:34.700 --> 12:38.130
which is placed inside block, but then we have an error.

12:38.300 --> 12:44.680
And the reason is that from outside of Falbe, we cannot access unlet because it's blocks code.

12:44.690 --> 12:50.110
And for a look like a false statement and functions also creates block.

12:50.630 --> 12:51.130
All right.

12:51.800 --> 12:57.070
When we use that declaration on each iteration, new variable is created.

12:57.080 --> 13:00.800
And in order to prove that, I'm going to change slightly this example.

13:01.810 --> 13:07.450
In JavaScript, we have built in a method called Septime Out, which actually works in almost a similar

13:07.450 --> 13:09.010
way as set integral method.

13:09.460 --> 13:15.700
The difference is that it executes function once after delite set time out method texte parameters.

13:16.390 --> 13:22.420
First one is callback function and the second one is amount of time, which actually defines delay before

13:22.420 --> 13:25.930
function is executed and it's expressed in milliseconds.

13:26.710 --> 13:27.130
So.

13:27.130 --> 13:27.460
Right.

13:27.460 --> 13:32.080
Set time out then insert anonymous function.

13:34.750 --> 13:38.590
Then place this castle, that log in the braces.

13:40.390 --> 13:46.840
In order to see better how Falbe works and how each iteration is done as a second parameter, I'm going

13:46.840 --> 13:50.050
to place here, I multiplied.

13:51.060 --> 13:56.730
Two, 500 milliseconds and also change led into VAR.

13:58.270 --> 13:59.920
Delete this cancel log.

14:02.000 --> 14:02.600
Reload.

14:03.540 --> 14:10.740
And he said that we have No five, five times that happens because one function is invoked at this moment

14:10.740 --> 14:12.260
for a loop is already finished.

14:12.780 --> 14:14.670
The value of verbal is five.

14:14.670 --> 14:18.230
And because of the delay, we get it five times.

14:19.170 --> 14:23.220
Let's change over into that and see what happens.

14:24.390 --> 14:28.300
You see that numbers are apart from zero to four.

14:29.010 --> 14:30.280
It's kind of strange, right?

14:31.080 --> 14:34.580
So let me explain what has happened here in case of that variable.

14:35.130 --> 14:36.840
We know that it's blocks called.

14:37.320 --> 14:40.640
So on each iteration, new variable is created.

14:41.340 --> 14:46.130
So on each function execution, there are different variables.

14:46.590 --> 14:53.490
And what you see here, I mean, numbers from zero to four, those are values of five different variables.

14:54.670 --> 14:55.350
Makes sense.

14:57.050 --> 15:03.440
All right, you may wonder what happens if we use customs instead of let some of you may think that

15:03.440 --> 15:09.470
because of that, after each iteration new variable is created, logically, we should get the same

15:09.470 --> 15:09.860
results.

15:10.430 --> 15:11.510
Let's see what happens.

15:11.510 --> 15:13.190
Change that into cost.

15:15.430 --> 15:18.960
And you see that we have an error and also zero.

15:19.580 --> 15:23.630
So this error is cost because we cannot modify the value of constant.

15:24.290 --> 15:26.180
Initially, its value is zero.

15:26.570 --> 15:28.780
On first iteration, it gives us zero.

15:29.210 --> 15:31.090
That's why we see in Council zero.

15:31.760 --> 15:38.540
But at the end of the first iteration, when the JavaScript engine sees a plus plus, you know, that's

15:38.540 --> 15:42.460
a plus plus is the same as I equals to I plus one.

15:42.950 --> 15:49.340
So which means that assignment operator comes into play and because of that we are not able to assign

15:49.700 --> 15:51.430
new value to cost variable.

15:51.980 --> 15:54.190
That's the reason why we have an error here.

15:55.070 --> 15:55.700
Make sense.

15:57.100 --> 16:01.360
All right, before we finish this lecture, I'm going to show you one more thing.

16:02.170 --> 16:09.340
So as you remember, in year five, we could create blocks for data privacy using immediately invoked

16:09.340 --> 16:10.420
function expressions.

16:11.140 --> 16:13.600
We have seen it clearly in our quiz application.

16:14.170 --> 16:20.440
In order to create APHIS, we have to open parentheses then right function.

16:22.570 --> 16:27.580
Then inside collaborationist, let's create variable A, which equals to 10.

16:29.740 --> 16:36.100
Then invoked the function and outside of function, right, consider log a.

16:38.680 --> 16:44.800
Of course, we have an error because we cannot get access on variable aid from outside Effi, but in

16:44.800 --> 16:47.510
Essex this stuff became much more simpler.

16:48.040 --> 16:51.220
We don't need to create, if it's anymore for creating blocks.

16:51.610 --> 16:53.660
We have just to use Calabrese.

16:55.150 --> 17:05.320
And let's create here, let's be which equates to, for example, 30, if we run it in council from

17:05.320 --> 17:06.370
outside of block.

17:07.390 --> 17:14.310
Then we will get an error because we cannot access a variable, be from outside of block, obviously

17:14.350 --> 17:16.690
the same happens with constant declaration.

17:19.360 --> 17:21.190
You see that again, we have an error.

17:22.190 --> 17:25.130
But there is one thing to note, if we use your.

17:26.720 --> 17:34.940
Vaki, but than those curly braces won't work because, again, verticalization is not Bloks called.

17:36.180 --> 17:43.560
All right, after all of this stuff, you may have a question when and where to use Örvar Let or concerned

17:44.130 --> 17:51.000
some of the developers are coming to use a in cost and ignore the declaration if you write ethics code.

17:51.450 --> 17:57.380
But some of them recommend the use of our declaration only in case of declaring global variables.

17:58.350 --> 18:04.980
I suggest to use Latin counts and ignore our declaration when you writing ethics, but it's up to you,

18:04.980 --> 18:11.700
you can take into account both recommendations also generally use constant declarations in most cases.

18:12.090 --> 18:17.820
But when you know that you would have to update dynamically values of variables that always declare

18:17.820 --> 18:18.960
them using that.

18:20.460 --> 18:22.080
All right, that's it.

18:22.350 --> 18:23.540
See you in the next video.
