Welcome back, my friends, to another lecturer in today's lecture, are we going to talk about S8 or
ECMAScript 2017?
So last time we covered S7 in now the time has come to cover these S8 features to the day.
We're going to talk about a couple of things.
We got to talk about pets start pet and trailing commas in function parameter lists and calls.
What a long name for for it will be object values.
Object entries in object keys.
Now object is not new, but I didn't never told you about this one, so it's my fault.
OK, so let's start with this.
So these are two string methods.
The first one that start and pattern for that, let's create first.
Name and let's call it and this guy.
Counsel, whoops, come on.
Console dialogue, we're going to cause a lot of the first name right away and let's go back here.
Let's see what's happening.
You don't need to see this.
So and these they're right.
So we control a lot.
So what we can do now, I'm just saying console the log and I'm going to see a first name.
Not bad.
Come on.
Bad start.
And because this is a method we need to use that curly brackets, I'm sorry, not brackets and let's
say at 15, dear.
So what you think will happen.
So there you go.
The and the is shift to the right for 11 spaces.
When I say 11, somebody will ask me, Will, there is a 15.
Well, 15 is our number.
But you need to also count this Andy character.
So we have two for so 15 minus four.
That gives you 11.
So the 11 characters or 11 spaces will be added to this string.
And this is good for indentation, right?
It's a very good for making padding.
So adding padding to the string on left and on the right.
So we have this for the left.
So let me just do it like this.
Bad stark.
To add.
Batting to the left, right, and I'm just going to copy this, but I'm not going to need everything
here, I don't need Yandi anymore.
So Pat and yeah, let's say to add padding to the right.
Off the string.
But.
Very good.
Now, Pat and.
It's been like this.
There you go, but you don't see it here, right?
You don't see it, but if I do this, yeah, you will see it.
So that's why I can say I can concatenate with DOT there.
There you go.
So if I put it here like 10.
That will move, right?
So it's adding actually six.
Right, it's not 10, one, two, three, four, five, six in here was 11, right?
One, two, three, four, five, six, seven, eight, nine, 10, 11.
Wow, that was super tired for me.
I just I didn't expect to be so, so tired for me.
OK, so we have done this to so bad start and end.
Now what we need to continue is to use these trailing commas and in function parameter released and
calls.
So listen, you don't have to worry about this part and.
It's not nothing but just a synthetical sure, right.
So what we can do now?
I'm going to create a function and we're going to test this inside a function because it's saying,
whoops, parameter list.
Right.
So where we do have parameter list, well, inside a function.
So const comma function.
Wow.
This is the first time that somebody's saying comma function and that is going to be me.
OK, so I'm going to say A, B, C, D and let's create here a narrow function and cancel the log a,
B that's it.
Because of the long and B and call it from here.
So you're going to say.
Karma function.
And just pass one, two, three, four.
So we have four.
Yes, we do.
OK, now I do have back one and two.
So what's the idea here?
We trailing commas, in fact, in a function parameter list.
Let me just copy this one.
So you know what's happening there.
Well, imagine if we add here a comma and if we save it, then it will not change the output.
And why this is useful?
Well, there are two benefits.
First, the rearranging of items is very simple because you don't have to add or remove commas if the
last item changes its position.
Now, this might confuse to you, but imagine here that we do have like a lot of parameter lists, a
big one.
And instead of the in one line what the developers are doing, not me.
So they're doing this same as we do with objects, right.
Good.
So now, instead of thinking about rearranging items and we don't have to remove her at commas at the
end because you want to move this one on top here, but the comma is going to stay there, right?
It's not going to mess around with the coat.
So that is why that is one of these useful benefits.
It's not much, to be honest.
The second it helps a version control system with tracking which what actually change.
So this probably does it make sense right now?
The last part is that it helps a version control systems with tracking what actually change.
And I'm going to just show it to you here.
In common, because we don't need this to run, it's not it's not going to run.
So here I'm going to say food and we change this.
From so I'm going to say from two, yeah, two, this is let's hear Essabar, right?
And but you don't you don't need to think about this too much.
Right.
And it's not even something that is pleasant for explaining.
You're not going to see much.
But just make sure that even if you put it here, comma, it will not change the apple.
What will happen if we put a comma here?
Right.
There is not going to change up because parameter lists and calls, because this is what we are calling
a function.
OK, but it's never a good idea.
I never put a comma there.
I'm not going to do that.
OK, but here you can get a new if you want and you don't have to worry about the commas.
OK, this was super weird for explanation.
Nice.
Forget about this.
Number three, now we move to number four, a number for a very, very good right object values, object
entries and object keys.
I'm going to start with object keys first.
I'm not going to say four here, but I'm going to say object.
So why do we need somebody will say, why do we need object keys?
Well, let's first create one.
Object call, user object, and inside this user object, we're going to have a couple of user users,
so user one, right?
So this will be just thumb.
Then we're going to have user two.
It will be Andy.
Come on, Andy.
Don't mess with me.
User three.
It will be Sarah and user four, it will be Angelina and put a breathing space there, why do you doing
this?
Good.
And there you go.
Now we have our object now object which is used when we want to loop through this object, as we loop
through the arrays using the foreach or Matmata, because we used it for each Matmata to other methods
for arrays.
But we can't use it on objects in this object.
This allows us so to that to use that functionality on top of the objects.
OK, let me show you to this one.
Now we need to say object keys just like this, and it will change a little bit color because this is
a reserved word user object.
We need to pass the entire object here.
Good.
Now I'm going to say for each and inside, I do have access to the key.
What is going to put that one in bracket?
OK, so if Consul Log.
And I'm going to say key, and here I'm going to pass the key here, right?
But that will give me this user one user to user three on each and every loop here.
But what about the value?
So these are key value pairs.
Well, the value we can just get it like this.
You don't have to type this one if you don't want it.
But just it's going to make more sense like this.
So the value we can grab it if you use a user object and we pass the key.
OK, let's see what this will come up to.
So this should have their karma.
Otherwise, it's complaining to us.
OK, so save it.
There you go.
We have key user one value, Tom, key user to value and the user three.
Sarah four will be Angelena.
Now, you know how you can loop through objects like they're on the rate and that.
Object that keys, I'm just going to write this for you guys so you can understand it.
So it's keys, not key is used when we want to loop through.
Objects.
As they are arrested and now, because I don't have enough space, I'm just going to put it here, OK?
Satisfied?
Nice.
What about the number?
Let me just grab this two number for a number five.
And number five, so I have a user object values and object entries, so these two features makes our
life even more easily easier.
We don't have to do this anymore.
OK, so what we can do.
So let's start with user and sorry, object entry.
So object entries will give back an array from your user object with all the entries you can get.
OK, let me just show it to you, this one, because it's super confusing, I know, so we need to say
object and trees in inside, we just plug the user object and we say for each there and I'm just going
to use the key word entry here.
You can use whatever you want.
We already know this things.
So Konza log the entry and let's see what's happening there.
Cannot convert undefined null object.
What's happening here?
I have no idea.
So this is happening.
You should say entry's not something bad.
Save it.
There you go.
Now you have four arrays with two items, four arrays.
So this will give us back an array from our user object, right.
So.
This is actually entries here, not confusing this values there, so this
will give us an array.
Of what?
User object.
Object key value pairs, because we have different key value pairs here, we have four, right?
So if we look if we cancel out the object.
The user object right, there you go, the user object is like this, and now we have one.
How many here you see property and value you see for then we have a four thou four arrays with two items.
So that is about the user object entries.
And now we need object values.
So the object values will give us the value back of each object property.
So it's not going to give this key value pair to us.
It's going to give us just a value.
Right.
And that is something where something very useful.
So I'm going to say object, not values.
And inside I'm going to plug the user object and I'm going to say for each so I can say value doesn't
matter what you want to say here.
If you want to say something else, you can do.
And I'm going to say Kanza log.
Value.
And I don't know why I'm not printing this in one line, it's going to work, right.
Let's see.
Very good.
There you go, I have Dormandy and Angelina.
Those are the values from the properties, so these so object values will give back the values of the
object properties.
These are the properties on the left side and these are the values, key or keys doesn't matter.
Keys nice.
There you go.
Now, you know all of it.
And I have some very interesting exercises for you.
Right.
Make sure that you do them in for the for the previous lecture.
So we have at Pat Start, Pat End and we have these trailing commas, what you can forget a little bit.
So in simple words, even if you add comma there, it will not throw you an error.
That's it.
Even if you had to come on there and.
Then we do object that keys so we can lub we can loop through the through the objects, same as we did
with Arae.
So we before, if we don't use this, we will not be able to use this for each or Matmata.
Right.
Object entries will give us back.
Properties and values in a Inari in one array in each time will give us back an array, each loop will
give us back on the ring and the last time object values will give us only the value of the properties
of the keys on left side.
Right.
These from the object.
OK, so there you go.
Now you know about S8 feature features and there is a one very big feature that I would talk about in
the next lecture.
Make sure you watch this lecture because that lecture, because it will be super, super cool and it
will be about async awake.
So that is one of the biggest feature of S8.
Right.
And it's built on promises.
On top of promises, so, yeah, we know what you need to know.
Promises as well in order to tackle that one.
So seeing that one and take care.