Hello, welcome back to another latest feature of ECMAScript, they keep adding new things, but this
is a really, really good one.
So the latest one is 20/20, has some really neat features.
And I want to show you some of my favorite ones.
You can see them right here.
Now, in this video, I'm going to talk about the street over here and then later on we'll have separate
lectures for years, 20, 20 promise all settled and also global this.
So those lectures will be titled East 2020 with the respective names, because these last two are better
understood once we go over a few different new topics.
So let's just focus on these three for now.
Let's get started with Big End.
And Big End is a really, really exciting new feature.
It's a new type in JavaScript.
What do I mean by that?
Well, now in JavaScript we have.
A type of.
Big int.
That's a new type, just like we have no, just like we have Bolian, we have different types in JavaScript.
Well, let's test out that theory.
Let's say we want to find out in our console over here.
If I do, type of it gives me the type of something, so if I do type of four, it's a number.
If I do type of let's say true, it's a boolean.
But what if I do a type of a really, really large number?
Well, that's still no, you see Big Int stands for Big Integer, but Andre, you just told me that
Big Ant is a new type and how come I don't see it here?
Well, to get the biggest type, let's clear this.
You simply add the letter and after a number, so, for example, I can do one, and so if I do type
of one RN, I get big ENT, but what does that really mean?
Here's a fun little JavaScript trick or a gotcha.
JavaScript has something called Max Safe Integer, and I'm going to link to some resources in this video
that if you want to dive deep, you can read about.
You see, JavaScript has something called a safe number.
And it can go up to a certain Insaaf integer, which is this number right here, but as soon as you
go a little bit higher, the calculations start breaking down.
So if we scroll all the way down here.
We find out that the Mac's safe integer has a value of this number.
The reason behind that number is that JavaScript uses double precision floating point format numbers.
That's a mouthful.
Essentially, there's a limit to how much information we can store in memory, what kind of and because
of the way JavaScript is built.
And this is actually common with other programming languages as well.
There's only a certain number that it can hold and big int solves this problem.
So let's experiment here, because I always love when learning a new thing to experiment and make sure
that we truly understand this.
So I'm going to open up the console once again.
And I'm going to try something, I'm going to say no dot max safe integer, which gives me the number
that we have here.
So this is the max that we can do in JavaScript.
So what if I do this number?
Plus one, does that work?
Yep, it works.
What if I do this number plus 10?
Does that work?
No, it doesn't, does it?
This number plus 10 shouldn't equal that, you see how we just broke something?
What if I do this?
No, right over here.
Minus one.
Oh, boy, it's messed up again.
Again, that doesn't make sense, does it?
So big int is used when we want to use a number that's larger than this max safe integer and we want
to do some calculations with it.
So instead, if I do this.
N minus one n.
Well, I get an operation between these two big events and you see here that it's working, it's minus
one.
Again, if we try and do our Max Integer over here and we do plus 10, we see that this doesn't work
as soon as we add NP to both of these.
There you go.
Our operations work.
So we're able to use Big Ent. as a new type.
Remember, if I clear this and I do.
Let's say one end plus two and, well, I get a big into a type of big event that we can do calculations
on, especially for big numbers.
But as you can see, we can also just do regular numbers as well as long as we enter.
And pretty, pretty cool most of the time.
You're not going to use this feature.
But it's nice to know and it's interesting to know that there are these limitations with JavaScript
and big and solves them.
All right.
Let's learn something even more fun.
Next one is nowish coalescing operator, actually, you know what, let's start with this one first,
the optional chaining operator and then we'll go into the nowish coalescing operator.
So let's pretend that we're playing Pokemon.
Hopefully everybody knows Pokemon greatest game as I was growing up.
I think it's still popular, though.
All right, getting sidetracked, let's focus here, let's imagine that we have a user and we'll say
Will Will is a Pokemon trainer and this user.
Has, let's say, the Pokemon, Pikachu and Pikachu.
Is, let's say, a species that is a mouse Pokémon.
It's got a height.
Of zero point four and let's say a wait.
Of six pounds, so height zero point four centimeters and six kilograms of weight.
Now, let's imagine that we want to find out the weight of Pikachu and hold it in a variable.
While we would usually do is say let.
Wait, and we'll say within here, we'll do Will Pokémon dot, Pikachu dot, wait.
So if we cancel, let's make this a little bit bigger.
And we'll do wait here.
Let's copy this.
Oh, man, we forgot to come over here, so let's try that again, let's copy this.
And we get wait of six, just to be clear here, I can just say.
All right, so this is working, but here's a problem.
Let's say we have a different user and this time the new user, his name is Andre and Andre doesn't
have Pikachu instead Andre has right you.
Again, a different kind of Pokemon.
It's still a mouse Pokemon, but some of the details are different.
Say the height is zero point eight and the weight is 30 kilograms.
So now, if I wanted to find out.
The weight.
Let's say, right, you.
And I run this command.
So let's say now instead of.
Right, you listeners do wait to hear, and this time from Andre's Pokemon, we'll do this if I run
this.
I get an error, cannot read property weight of undefined and why is that?
Well, because Andre doesn't have Pikachu, right?
We don't have that Pokemon instead.
We have.
Right.
You so when we tried to grab the Pikachu from the Andre Pokémon object, it's going to say, er.