Welcome back, ladies and gentlemen.
Today's lecture will be super short, but we will talk about new feature in ECMAScript nine, and that
is ECMAScript 2018.
So this feature was released in 2018.
And you should be happy because we are progressing very, very fast.
And, yeah, you should be happy with your progress.
Now we're going to talk about spread operator.
We did spread operator honourees.
Right.
Let me just remind you before we start to talk about Sprint operator on objects.
So I'm going to say here a spread operator on arrays is six.
Nice.
So what this was is six feature.
So I'm going to create an array called Cars in stock and I'm just going to let's put a higher rate.
A lot of big descriptive name in here.
I'm going to pass some random numbers.
How many cars we have in stock.
Right.
So how many cars are there in the yard?
So 18 here, then 33, then 88 and seventy nine.
You can put any numbers you want.
OK, now let's create a function that will calculate and return back the whole amount of these elements.
So cost Colque in stock.
You can call this the function, anything you want.
Right.
And let's put here A, B, C, D, E and F.
How I know this well, because we have this amount of elements here in the array.
OK, so let some or some it doesn't matter.
A plus B, C, D, E, plus F, and we return to some.
Now let's use the spread operator so called a function.
So how we do this const result you can just cancel.
It looks great, but I'm just as a cog in stock and I'm going to pass here using the spread operator,
the array.
Now the last thing we need to do, cancel that log.
The result.
Total number of cars in the yard as a here, we're going to pass the result, not return result where
we get save it, make sure the electorate linking your index file.
The total number is fifty seven nights, so if you manually do this, you will see that is 350.
So if you manually at each and every of this, you will get three fifty seven.
Now, what a spread operator is doing.
The spread overeagerness doing it spread all of the three elements over the parameter release of this
function.
Right.
How cool is this?
This is super, super useful.
We can do it one by one.
We can pass in multiple here parameters like 125, 14, 18.
But that's not the point why we can why we need to do that when we have the spread operator.
Now, that is pretty much it.
So the second thing is to use spread operator.
On objects, so this is the new thing.
So this was just to remind you how this was done in year six.
Now let's create here an object concept called cars in stock.
And you can say Olby for object or object.
Right.
And this object will have BMW or BMW beefing Audi or Audi 16, Mercedes or Terrasse 24, for example.
Any numbers you want.
And A for 18.
Very good.
Now, how are we going to use the spread operator here?
Well, let's do this consed BMW, right?
Come on, if I can, Deborah, and then I can use the rest.
Now I'm going to pass here the cars in stock object and that's pretty much it.
But if I save it, you're not going to see any changes here.
OK, but look what is happening now if I can't unlock the BMW.
Now I have 15 or the value that I had in the BMW, cool, so I get the value using the spread operator.
OK, now these three, does that rest?
What, you think it will give it to us?
It will give something like this.
I can say rest.
So it will give us another object containing autistics, Mercedes's and for nice.
So that returns the rest of them as an object with their key value pairs.
Right.
And that is pretty much OK.
So.
We can access this like this, Audy, we can access it by Mercedes's, then we have another, but that
is the power of the spread operator.
So now that you know that you can use it on even on the objects and make sure that you're doing the
your exercise, because they will be pretty much more interesting than this.
So I don't want to reveal everything here because I want you to practice on your own.
OK, that's pretty much it for this lecture.
I see you in the next one.