WEBVTT

00:01.020 --> 00:06.810
In previous lecture, we have discussed how spread operator works and now I want to introduce you new

00:06.810 --> 00:13.230
type of parameter in ethics, which is the rest from syntactic perspective, they are expressed the

00:13.260 --> 00:14.300
exact same way.

00:14.580 --> 00:19.590
We have to use three dots, but w parameter works in an opposite way.

00:20.190 --> 00:31.590
So let's create simple function costs a equals the function and insert here two parameters X and Y.

00:34.280 --> 00:40.100
Let's run in council with some of those parameters, right, council log X plus Y.

00:43.230 --> 00:54.630
Then called the function and place here more than two arguments, right, 10, 20, 30 and 40, if we

00:54.630 --> 00:58.860
rule out, then we'll get some our first and second arguments.

00:59.730 --> 01:02.790
Regardless of that, we have pushier more than two arguments.

01:03.270 --> 01:05.690
Function is working without any errors or bux.

01:06.240 --> 01:09.030
But again, we get some of only first two arguments.

01:09.600 --> 01:16.020
So actually, it's interesting how we can use the rest of the arguments in why we have special Keywood

01:16.020 --> 01:23.610
arguments, which represents arguments of function and returns array like object, its index based and

01:23.610 --> 01:24.720
has the length property.

01:25.560 --> 01:28.890
Let's at first thing counsel what arguments look like, right?

01:28.890 --> 01:31.470
Consider log arguments.

01:34.460 --> 01:39.860
That revolt and you see that we have an object which looks like an array.

01:40.340 --> 01:43.870
The items have index numbers and also it has length property.

01:45.200 --> 01:50.240
Also, as you notice, it doesn't contain only third and fourth arguments.

01:50.510 --> 01:52.270
It includes all four arguments.

01:53.600 --> 01:59.600
So in order to use third and fourth arguments and calculate the total sum, we can write the following

02:00.080 --> 02:01.220
plus arguments.

02:03.080 --> 02:07.220
And for third arguments, we have to place the index number two.

02:08.630 --> 02:13.820
Then again, plus arguments with index number three.

02:15.660 --> 02:20.070
Reload and we have 100, the sum of all the arguments.

02:21.040 --> 02:27.130
As we said, arguments is an array like object, so in order to use our methods with it, we need to

02:27.130 --> 02:28.630
transform it into array.

02:29.380 --> 02:34.120
I'm sure you remember S5 approach, which we have seen in previous videos.

02:34.630 --> 02:39.880
So we need to write a red DOT prototype.

02:41.270 --> 02:43.950
Dot, dot, dot com.

02:47.310 --> 02:53.700
So if we reload, we will get arguments collection, but in this case, as a right, I would like to

02:53.700 --> 02:56.820
note that arguments object doesn't work with our functions.

02:57.330 --> 03:06.990
If we change this regular function and right here our function, then we will get an error telling us

03:06.990 --> 03:08.750
that argument is not defined.

03:09.300 --> 03:11.470
All right, in Essex.

03:11.490 --> 03:16.980
There is no need to use arguments, objects, because new version of JavaScript allows us to use Reath

03:16.980 --> 03:20.880
parameter, which is more flexible and convenient than arguments.

03:21.480 --> 03:23.010
Let's delete those lines.

03:23.010 --> 03:25.050
And after X and Y.

03:25.060 --> 03:25.500
Right.

03:25.530 --> 03:26.750
Dot, dot, dot, dot.

03:27.810 --> 03:34.290
Actually, it's not keyword you can use here anything you want, like, for example, arguments or something

03:34.290 --> 03:34.640
else.

03:35.640 --> 03:38.640
But remember that using three dots is always mandatory.

03:39.660 --> 03:42.420
That's the first thing Castlebar about this parameter gives us.

03:42.420 --> 03:42.780
Right.

03:42.790 --> 03:44.460
Cancel that log rest.

03:47.590 --> 03:54.190
So as you see, it returns an array, but only with two arguments, third and fourth, which actually

03:54.190 --> 03:55.780
are missed as parameters.

03:56.890 --> 04:07.690
And in order to gather some of these arguments, we have to write X plus Y plus rest with index number

04:07.690 --> 04:13.720
zero and then plus rest with index number one.

04:16.630 --> 04:19.540
So we have, again, total sum of arguments.

04:20.520 --> 04:25.770
All right, let's use another example and see better the power of parameter.

04:26.910 --> 04:28.560
Create consent family.

04:31.180 --> 04:37.260
Suppose that we would have several members of family, those persons would have common last name.

04:37.270 --> 04:40.450
So let's place you as a first parameter.

04:40.450 --> 04:41.140
Last name.

04:43.580 --> 04:50.150
And then let's assume that as arguments, we would have names of family members for that, I'm going

04:50.150 --> 04:52.040
to use a rest parameter, so.

04:52.040 --> 04:54.050
Right, dot, dot, dot names.

04:56.510 --> 05:01.590
Then use erode function because of that the parameter returns array.

05:01.970 --> 05:06.480
Therefore, I'm going to use a Ray Hopper method for each and using this method.

05:06.500 --> 05:09.940
We will define first names and last names for each family member.

05:10.580 --> 05:11.000
So.

05:11.000 --> 05:11.420
Right.

05:11.420 --> 05:13.700
Names for each.

05:14.700 --> 05:21.510
Then as the current item right name, which is followed by eral function.

05:25.150 --> 05:27.430
And then running castle.

05:30.250 --> 05:31.510
Name and.

05:32.970 --> 05:33.690
Last name.

05:35.280 --> 05:36.690
Using tablet strength.

05:40.110 --> 05:48.060
All right, let's invoke dysfunction right below family for the last time, I'm going to insult your

05:48.060 --> 05:55.260
argument as, for example, Smith and for names of our family members.

05:55.920 --> 06:01.350
Let's place your neck then, Jane.

06:03.650 --> 06:04.130
Bob.

06:05.930 --> 06:07.220
And Jessica.

06:09.960 --> 06:11.160
Let's reload the page.

06:12.370 --> 06:18.130
And you said that we have here persons with different names, but with common last name, Smith.

06:18.430 --> 06:18.880
All right.

06:19.330 --> 06:23.300
So you see how convenient and also how simple is to use race parameter.

06:23.950 --> 06:30.190
Also, you need to remember that we always have to place a parameter at the end inside parentheses.

06:31.270 --> 06:37.180
It doesn't matter how many arguments you will have, a parameter will work with all arguments which

06:37.180 --> 06:39.460
are not represented with parameters.

06:40.480 --> 06:43.740
OK, it was all about race parameter in Essex.

06:44.050 --> 06:45.250
See you in the next video.
