WEBVTT

00:01.200 --> 00:06.900
In this lecture, we're going to talk about one of the most popular new features of ESX, I'm going

00:06.900 --> 00:12.810
to introduce you what area functions are, as we said, the main goal of release of ECMAScript 2015

00:12.810 --> 00:15.600
version was to minimize the amount of code.

00:16.020 --> 00:20.880
And one of the perfect examples to achieve that in Essex is to use eral functions.

00:21.900 --> 00:27.600
First of all, I would like to mention that generally arole functions do not completely replace standard

00:27.600 --> 00:30.290
functions which we're using as usually.

00:31.050 --> 00:36.450
And in order to avoid unexpected results in errors, you need to definitely understand well in which

00:36.450 --> 00:40.020
situations and in which case this is better to use function functions.

00:41.060 --> 00:47.690
Again, in this lecture, I'm going to compare our functions to standard function declarations, so

00:47.690 --> 00:50.300
I'm going to create a simple function expression.

00:50.910 --> 00:53.720
Let's create constant variable multiply.

00:54.670 --> 01:01.300
Which equals to anonymous function with two parameters, X and Y.

01:03.090 --> 01:10.020
Inside that function, let's create let's variables that which will store the multiplication of X and

01:10.020 --> 01:15.660
Y parameters and then return the value of Z.

01:16.780 --> 01:24.220
OK, let's invoke dysfunction with some arguments, right, cancel that log, multiply and place here

01:24.220 --> 01:26.740
as an arguments five and six.

01:28.380 --> 01:34.440
Revote, and we have, of course, 13, as you see, this function expression does not contain lots

01:34.440 --> 01:36.920
of characters and it's very easy to read.

01:36.930 --> 01:42.360
But thanks to general functions in Essex, we can write this function in more concise way.

01:43.020 --> 01:49.560
For that, we have to get rid of Keywood function then after parameters.

01:50.530 --> 01:57.010
We have to place erro, which actually consists of equal and greater than signs, you may be surprised

01:57.010 --> 02:02.920
how this function expression works without the keyboard function, but if we reload the page, then

02:02.920 --> 02:04.140
we will get the same results.

02:05.020 --> 02:09.250
You might think that's why do we need to replace function keyboard with that arrow?

02:09.620 --> 02:15.820
I mean that at a glance, there is not a huge difference between the amount of code in this case and

02:15.820 --> 02:22.210
in previous one, but actually using eral functions, we can transform this function into more concise

02:22.210 --> 02:22.510
form.

02:22.780 --> 02:28.020
What do we have two or more statements inside Culebra basis than in its sixth version?

02:28.030 --> 02:37.120
We have to maintain those Kolob races, but if we return here directly X multiplied to Y without that

02:37.120 --> 02:37.690
variable.

02:39.350 --> 02:46.360
Then we can remove these color braces and then remove even the written keyword.

02:48.690 --> 02:54.670
Now, we can say that this is really short and concise transformation of function expressions.

02:55.080 --> 02:56.910
This is a really great feature.

02:56.910 --> 03:02.460
But on the other hand, to read the code is a little bit hard, especially when you first introduced

03:02.460 --> 03:03.050
this feature.

03:03.540 --> 03:06.200
But I think that it's an issue of practicing.

03:07.410 --> 03:12.480
So in this case, we have two parameters here, and that's why we surround them with parentheses.

03:13.050 --> 03:20.340
But in case of one parameter, let's suppose we have only X, which then is multiplied to 10.

03:24.270 --> 03:30.180
Then we don't need to use that parenthesis anymore, reload the page and you see that it works.

03:31.650 --> 03:36.000
So, again, when we use only one parameter, we can write it without parentheses.

03:36.900 --> 03:45.780
All right, let's see what happens if we don't have parameters, let's delete X and then write five

03:45.780 --> 03:49.950
multiplied to ten and also remove this argument.

03:51.270 --> 03:51.870
Reload.

03:53.600 --> 03:59.420
And you see that we have syntax error, JavaScript engine cannot recognize what this error is here.

03:59.930 --> 04:06.680
So when we use function expressions and we don't have parameters, then we have to place your empty

04:06.680 --> 04:07.380
parentheses.

04:08.090 --> 04:09.710
So you see that it works now.

04:11.030 --> 04:11.570
OK.

04:12.540 --> 04:19.110
Let's say we want to return as a value and object, but without using return Keywood, if we simply

04:19.110 --> 04:22.050
create an object with property first name.

04:24.330 --> 04:31.620
John, then we will get in counsel undefined, so in order to avoid this unexpected value, we have

04:31.620 --> 04:36.360
just to surround this object with parentheses and that it will work.

04:37.870 --> 04:43.810
All right, one of the key points regarding Arrow functions is that we can use them only with anonymous

04:43.810 --> 04:44.440
functions.

04:45.040 --> 04:50.300
If we want to declare function statements, then we have to do it in a usual way.

04:51.490 --> 04:52.000
All right.

04:52.420 --> 04:57.540
In this lecture, we have discussed just the basic syntactic changes about functions in ethics.

04:58.150 --> 05:03.160
Let's move on to the next lecture in which I'm going to show you some more important features regarding

05:03.160 --> 05:04.000
arole functions.

05:04.930 --> 05:05.620
Let's go ahead.
