In this lecture, we're going to cover the most important feature of S8 or ECMAScript, right?
We did talk a little bit about weight, not little bit actually explained the whole process when we
were dealing with promises.
So if you want to go back, you can check those out and you will get clear but clear idea.
But in the future, in the next lecture, I will just mention a little bit more about them.
And so if you haven't watched that one, you can still watch this next one and you will have idea how
we consume promises, because this is nothing, how we write promises.
And in the next lecture, I will not spend a time explaining how we did write the promises.
So that is my recommendation to go back and look.
Now, first things first.
The eight features that were released in 2017 are a couple a few more compared to the first seven.
Right.
In this video, I will just mention the most important ones.
These are the screen functions that start and pat in.
And after that we have object values and object entries before we used object keys.
So I'm going to touch on that one.
So I've opened up here any so you can open up any JavaScript file that you want.
You can name it anyone you want.
I'm not going to give you this one because this is so simple in most of the code.
I'm going to run back to the console here, console console lock in this one.
So it's not going to so it's not going to be something useful here.
No, I'm doing this because it will be easier for me to just write it down and explain it to you.
Now, first things first.
Let's try to count in the console, OK?
I'm going to write a string called Tom.
Now, I'm can I can use on Pad Start and I can add a number here.
So look what he's doing.
So I've had a number.
And actually what it creates creates seven spaces before Tom.
But somebody will ask me why seven spaces.
Because I put ten.
Well, because Tom has three characters, three miners.
Then it will be seven.
Right.
I can use the opposite of this.
It's called pad and and it will give us seven spaces after the storm all together.
They will be ten.
Right.
So don't get confused.
Don't think that here it will at ten spaces now why we used it.
So this is the way that you can actually give a paragraph batting or street batting or anything that
is connected with text a line.
Right.
So that's pretty much about these two bad start at Bannen.
Right.
These two features.
Now, let's go back to the objects now.
The first way that we run, right.
The object was the object key.
And I'm going to write object here and I'm going to say object.
And this object will store first.
I'm going to see a first name and I'm going to say for the first name.
I am going to give here thumb, right for the last name, I will say Cruz and what is your occupation
actor right.
So this is how we write an object before this is a key value pair.
And before we just use we want to look through when you see this is give you that uneasy look, I need
to loop through this object.
I need to get the values, the keys, whatever is there.
But this is not unary.
You can write all of the methods for the area.
Right.
That's why we had some problems in our Berney project that we did.
So we need to convert this back an object to Honoria.
But here there was just something more powerful.
And we can use the object values and object entries.
But first things first.
I want to show you how we write it before.
So I'm going to see here object that keys and here I'm going to pass the entire object that we created
up above right here.
I can use the foreach now method on it.
And here I will say, OK, I have the access of the key and the value up here.
Right.
And I'm going to write the arrow function here and I'm just going to simply Konza lock the key in the
object with that key.
Now, let's copy this one here.
Actually, that's copied in the both of them and put it back here.
Oh, let's first clear this one up and semicolon and hit enter.
Here it is.
So it's going to give me the first name, time, last name, Crucis.
Give me the key value pair.
Right.
But now this.
Even with S8, it can be done a little bit different so we can use so the new way we will grab the values
from each object.
Look at this now here what we can do is we can use the object still value and it's going to be values,
no value.
And I'm going to pass the entire object here.
And again, I can do the foreach, but here I will need only the value.
Right.
And let's write another function and console lock this value.
So what's the difference, somebody will ask.
Right.
Well, let's put it like this and see what's happening.
OK, now I've got only the values, which is super, super easy now.
So I said Tom Cruise and actor.
Right.
Some great values for each object item.
Now the entries.
So this was the object and values.
We have the object entries.
I'm just going to copy it and I'm going to change these two entries.
Right now, the entries will create a new era with the two parameters, the key and a value from the
object.
OK, and this is, by the way, the most powerful with the entries.
This will produce three different areas with two length of two.
Right.
So the first time I have.
So in a superposition, I have the first name of that object, the second position or actually the first
position that will have the name.
Right.
So this is how the object entries working.
So they will create and two elements, every with two elements inside.
Now here we have more control than object and we can use the map the each because we now have the areas.
We can use any function here that we want.
OK, so to make this more easier, I will write a real case scenario here, for example, to I will
select object users, for example, this object of the users will return us the least of the user names
and their user name.
Right.
So actually these probably imagine that it's coming from some server and I'm going to say user name
here, zero in column here again column.
And I will say Rick here right now, the second one I will just copy a couple of times.
One, two, three, four.
So user name of one actually will be Tom.
Username of to imagine this is coming from somewhere from the server and it will be a Jack.
This will be Logan and this will be OK, Ian.
OK, so here I will say three and four.
OK, now we have four user names back.
Right, so let's run this in when using the object that entries.
That's why I didn't copy it.
I've no idea.
So object that entries.
But remember to change the object here and let's keep it interesting.
Pasted down hit enter here is I do have this user name Zero and Rick.
But now the cool thing, what we can do is we can also get the new screen user name and the number in
the name of the user name only.
I need the number actually and the user name.
Name.
Right.
So this little bit of tongue twister for me.
So I just want this number here.
Zero column and the name of one column, Tom.
OK, so how I'm going to do this?
Well, it's super simple because we can use on the strings something that we can't use straight on the
object.
So I'm here.
I'm going to see a return.
I'm going to return a value because this is a value of zero, right?
This is a value.
If I go back here, it's a value zero.
And it's always going to be even for the secondary, it's going to be value zero.
And I you write it inside, then replace I can use that string method and I will say replace the user
name.
So it will find the user name until here.
And I want to replace this one with what.
With nothing.
And this will concatenate me the value of one.
Now I will have a readable output that it's working for me.
I'm just going to copy it here.
I'm going to pay it back and I'm going to do it like this and.
It's not working for some reason and it's not working, I delete it, it's not working because we didn't
consulate lock so we can cancel this log.
So it's harder for me to write it here, so I'm going to consult before I was just returning it.
Now, here it is.
I do have zero free time Jack logo in Ian at the end.
So this is how we can use the object entries.
So instead here of returning, you can Cosla and you can just make this more meaningful result.
Now one more thing before I go here, I want to mention that what we can do is, oh, actually in year
eight there is a something that is considered as a normal way of writing and this is called trailing
commas in function parameter list and calls.
What the hell is this?
Right.
Well, it's nothing special, but let's write a function called some.
And inside this function, I will have a couple of parameters here.
A, B, sorry, A, B, C, the and I won't put extra comma here and I will write the error function
like we did before and I'm going to cancel log the E plus B and in order to work this one, we need
to call it some one to three for an extra comma because here we do have extra comma.
Now if I copy this, clear this result, paste it back, hit, enter and read a declaration of some.
OK, first I need to refresh this one and it will work because I've used that book before, so I was
trying to show you something that I've used before.
Right.
So can some.
You now have four parameters here, but additional comma.
Why is this?
Well, this is what the they say trailing commas and function parameter lists and calls.
So I need this.
Wow.
Imagine that this will be useful only if you have a long, long, long parameter list here, like a
twenty.
And before we just going to start writing like this in order to make to be more readable.
So this is only synthetic shuga of our write.
But this comma actually will not throw you an error at this stage.
And that is the what I want to show you.
So even if you put a comma here, if you have a long parameter list, then this will not throw you on
any any error.
That's pretty much it.
So nothing special.
The first one, this one is pretty much I've never used it.
So you don't have to worry about it.
But object the entries and object.
The values are pretty much cool before we were using this.
But now we can use more things because we can convert with entries the object to an array and for the
arrays.
We do have a lot of functions and the first one was spatting.
Start embedding and that will add spaces before the end of the string.
These are just for the strings.
So the async await.
Now, the async away will cover a little bit in the next lecture, but it's covered in depth in one
of the previous lectures.
So if you want go back, just watch that promises in Async Away, because that is the most important
part of its eight features.