Welcome back, ladies and gentlemen, today we are going to do S11 features in the reason why I haven't
released what we are going to do in this lecture, because I don't know how long it will take, because
there are a couple of features that I want to go through.
So this is is 11 or ECMAScript, 20, 20.
Now we are getting closer and as soon as they release the new features for twenty twenty one, I will
just upload them as well.
OK, now in this release, there's a one interesting feature called Big Integer.
Now I'm just going to put it here as a number one, and it's called Big Int.
So this is a very interesting feature.
And in JavaScript there is a limitation of a no representation of what this means.
There was a limit, max limit, how big the number can be.
Now, this might be confusing because we never talk about this, but let's see, this can be represented
with a number of primitive.
So, OK, now, if I do console that log and if I say no like this, this is the number of primitive
and say Max safe integer, they should give me this number.
So this is the max safe integer that we can use.
OK, so you can store it in a can in a concert if you want Max number like this.
And put it there, right, called the max number, so this is the maximum number that we can use in
JavaScript.
So dear, how this number, it's coming, but where this number is coming.
So this is two.
So how you read this two to the power of 53.
Right.
And we can write it like this to power of two, comma.
Fifty three minus one.
OK, so if you do this in your calculator you will get the same number.
OK, so that is how this max safe integer is calculated.
So let's do something here.
A little bit of experience const first number.
Let's do it like this if I can type it right and let's say I'm going to say no.
Bus one, OK, and Consed second number and I will use the same one, but I'm going to add two now I've
told you that this or I can use Macs number plus one, right?
Yeah, because we have a constant max number plus one and I can use Max number here as well.
Plus two now basically.
Because we reached the limit here with this one, and if I want to add one or two to this number, then
then I will have problems.
Look at what will happen.
So if I comes along and I will say first, no.
And let's do first number.
There you go.
It's a little bit different, right?
It's one extra because we added one right to the first one.
And let's put it here, Max integer limit.
Right.
And someone will say, well, the max integer limit, it's this and I get this.
So what's the problem here?
Well, look what I bring out the second one.
Now, this should be 93 again, right?
But look what will happen.
No, it's not going to go there, right.
Because there is a limit.
So if we do some calculation with the numbers greater than safe integer, then we have a problem.
And that is why big integer is coming.
So big integer is actually inbuilt object that provides a way we can represent whole numbers larger
than this power of two.
Right.
So two to fifty three.
So that is why the they created this big integer.
Let me just sit here and say make it so it's an object.
And that provides a way how we can represent whole numbers larger than this element here.
OK, so let's consider the big integer and say const.
Let's create a variable called big.
And put it like this here in Dejour.
And this is actually this where is taken, you can just begin and it will be or integer, let's put
it like this integer and that will be equal to big int.
So no doubt, Max.
Not actually, Max, safe, no.
Max, safe integer, and let's council lock the big integer now and see what we have.
Wow, you see that we have the same one on top, but we have it's a different color and we have and
at the end, OK, just put it here.
Big integer.
Very good.
So.
Let's add another here.
Console that law.
I'm just going to do it like this, so I'm going to use these big integer and I'm going to add a one
extra like I did it here.
But in order to do that, I need to use again, big in.
Like I did here, and I'm going to pass one here and I'm not going to save it.
And this will be at 2:00 and here I will say.
Plus one, right, just to know.
Big in plus one, and this should be big and plus two, right?
And comma here and now, save this, guys.
Well, there you go now, plus one will give us two and plus two will give us three.
And so.
There you go.
Now, if you observe, you can see that the Beacon Theater and its end to the end of an integer number,
right?
And that is pretty much it.
What about the big integer now be integer is not same as no country.
The team is number, so it is different.
And we cannot use directly to a math object.
We cannot be mixed with a number of instances and doing calculations with it.
Right.
So you can mix numbers with big integer.
You need to do a typecast, but you're not going to worry about that thing at the moment.
So I'm just going to tell you that because the numbers has its own limit, this is a primitive number.
That's why we can access no massive integer.
There's a limit.
There is a this here.
I'm just going to.
Can I copy it?
Yep, I can.
So this is the max safe number, but now if you want to add one or two extra to that number, it's not
going to work.
So any calculations above this number will not be valid.
That's why they introduced this big integer.
But if you want to use it in connection with the numbers, you need to use typecasts.
Right.
So that's a little bit of work for us.
And we are not concerned of that.
But you need to understand there is a big integer and that's a new addition to the Atmos script 2020.
Now, the next big thing in this is 11 is this operator.
It's called mulish with double L coalescing.
I can't even pronounce it.
And operator, so newly leasing operator, and this is a logical operator and it's represented with
this double question marks.
Now it's a logical operator and deals with no or undefined values.
With no, I'm just going to write it here or I'm going to do this and fine values so or mulish values,
right.
That's why it's called not knowledge.
So it works a similar way as a logical operator.
We did double pipe right here, the pipe one that was logical or operator.
Now, it's not the same as logic, logical or operator.
It's a contrast to that.
Right.
So that's why we're going to do it here.
A couple of the couple of exercise, actually, just to make sure that you understand this point.
Right.
So a logical operator, it generally returns the left hand value if it's Truthy or it will return the
rightside value if it falsey.
OK.
Let's see what our just said, wow, that was confusing, so I'm just going to say console that lock
and I'm going to do it here.
So zero.
Or what's happening here, so zero or.
Five, what you think it will get us, let's save it, it will return us five.
So as I said this generally I'm just going to write it down because you're going to forget this one.
So logical or operator returns the left.
Hand value, if.
True.
Else.
Returns the right now zero, it's considered as a false or a false value, and that's why it returns
the right side.
There is the definition.
OK, so let's test this out.
And to make this one look to look a little bit prettier, just based.
This one here, a comma.
And there you go.
Now, also, you can do it.
This comes to this.
Nice.
So let's do two more examples.
Now, what if we have I'm going to put a double quotes here because I want to use an empty string here.
So what if I have empty string here and let's say Rick here, but you think it will return, right?
Let's do the same thing.
Empty string.
And Rick on the right side, so the logical operator returns the left end value, if it's true, else
returns the right value, right.
OK, so let's comment on the last one.
Save it now.
It returns, Rick, because we have what, falsey value.
It's nothing.
There is an empty string, and that's why I took this rightside.
OK, let's confirm this thesis here.
So cancel that lock in.
I'm going to say here again, double quotes.
Because if you want to use single quotes.
You need to use double quotes outside.
Now see here, Rick, and let's put it here, Andy, that both are what?
True values, right?
Let's put it here, Rick.
Let's put it here, Andy, now what you think it will get us, it will get the first one, the left
side always returns the left hand value if it's true right that.
There you go.
Now, the knowledge calfskin operator is running a little bit of different, so it returns the left
hand value.
So I'm just going to write this returns.
Left hand.
Value when the value is not no or undefined, what else returns, right value.
Very good.
Now, let's test this out.
So I'm going to use the first line here, but instead of the operator here, I am going to use double
question marks or knowledge call asking operator, write what you think it will return.
It returns zero, right?
It returns left hand side, then the value, it's not null or undefined.
Cool, because this is not now zero is not null or undefined.
That's why it returns a zero back to us.
Now, let's do with empty strings here.
Right.
Let's try this one.
And I need to close this one here, this one good, so I have empty string, then I get back the empty
string, but you don't see it, but that's the empty string back, so it returns the left hand side.
OK, let's check out the teases that it will return to rightside value if it's now or undefined.
Hmm.
Let's test this out.
So let's put it here.
If no.
And five will return, what, five good.
Nice.
Let's do this one undefined and so if the thesis is right, it will return us again five.
All right.
Otherwise, it's always going to return to left operator here you can say operand.
Nice.
So there you go.
The knowledge callsign operator is this one and yeah, that is pretty much it.
So.
You need to understand, so it is not possible to combine with other logical operators like and so you
can't combine it together with and and or or this one so you can combine them.
Right.
But can be used when we include parentheses so we can use parentheses, so we can include both of them.
Right.
So let me just do one example here.
Combination.
Of awe and the knowledge, right, so let's say this console that long.
Um.
So we need to say here, double inside, we need another pair of brackets, so let's say Rick here,
I wasn't planning this to include, but yeah, let's do it in falls.
Now, outside, I will put the knowledge.
And let's see here.
My last name.
So what, you think this will return back to us?
It will return, Rick, right?
Good, so it is working when we use a combination of all this knowledge and or operator, good, but
you need to use the parentheses.
It's not going to work without this parentheses.
OK, let me just test this out and to show you that it's not going to work.
See me saying, yeah, it's saying missing the after the argument list.
Good.
There you go.
So the next thing that I want to explain here is called optional chaining.
And it's looks like this dot and questionmark, OK, what is this?
Before doing this, I would like to create an object, so let me just write it here.
Optional genin.
And this is not that very hard to understand, but it is a little bit tricky, OK, to grasp.
So I'm going to create consed here person object in this person object will be nested right.
So in order to check the nested object we need to run alse condition to see to avoid any undefined values.
OK, let me just show it to you.
So name here it will be.
You can put any name here that you want.
Now developer.
True.
Then we can say or says.
So this is where the nest egg comes from, and I will say two courses, very good.
Then again and let's see.
Um, the the true nice, so there you go, we have a nested object and you should know all about objects,
right?
OK, so.
Now, if I want to have this access here to get access to this truth, we usually do a safety check.
So we will say if a person and person that course and we will see in person that cause.
We should have courses here, right, courses that should be good courses, courses, it's more logical,
right?
And then I can see two courses.
Then if this condition is true, let's say Konza like.
It pass means that everything is working OK, is getting there so I can safely now console lock.
The person that.
Courses that two courses and web dev.
There you should give me back to, right, if I have somebody here like two courses, it will give me
back to courses, right?
Let's do this.
Two courses, nice or true?
Doesn't matter.
So this can be changed now with this changing operator, because actually what we did here is this is
called a change, right?
We change multiple conditions.
We check if they are true, then we went here in this condition.
And we just if everything is true, then this whole line will be executed.
Right now, the optional training, this will be replaced here with something like this.
So we can straight away we can see Conjola now, person.
And I'm going to say questionmark that way.
I think I'm not real a bit here.
Should be questionmark.
Not right, not questionmark.
OK, I'm sorry about this guys.
So yeah, I'm being it's been a long day for me so now I will say courses.
But then again, questionmark not.
So we can take courses, then we can say two courses, then questionmark not and in the end it will
be weap dev, right.
Let's comment on this part here and save this guy here.
There you go.
I have two courses as well.
Let's change this back to true.
To tell you that.
To show you that it's working.
There you go then.
It is true.
So this is pretty much more simpler than this, right.
So this is the chaining operator.
Now, if we made a mistake here, of course, for example, it will return us undefined.
Right.
Nice.
So if you have this one so you know how to deal with those errors.
There you go.
Now you know another.
Optional chaining operator.
The next thing that I want to discuss is called number four, private class variable, and what this
will do, it will restrict variables to be for internal use only.
But I need to create a class for this in order to show you.
So the number four will be private.
Oops, class variable.
OK, now let's create a class called person and how we would create a class.
We use the key word with capital P, right.
And class keyword as well.
So class capital P.
OK, now here I'm going to create a variable called my name.
OK, and this my name will be right now if I want to do, if I want to create a private class variable,
all I need to do is to get this hash symbol before it.
Now if you use Firefox or any other browser, this might not work.
It will throw you that.
Our class are not supported yet.
Right.
But the Google does support this private class variable.
So just adding hash before the variable makes it private.
These assure us that this variable cannot be accessed directly from outside.
OK, let's create some method here that you say get details and this method, that method will print
the details so I don't put a constructor here.
So this is just a very, very simple example.
Please, just to make sure that you understand the private class variable.
So return this that.
Mining, right there you go and eat automatically at the hatch, right?
So let's instantiate this class here and say const.
PERSON one Well, let's call it Rick by my name.
You can call your name.
So how instantiated an object from a class with a new keyword and we add the person.
Now we're going to pass the we're not going to pass anything to the constructor.
Nice.
So I can do calls along now.
So, Rick, I want to access this, get details function.
But because it's a function.
And the OP, which would be, Rick, because it's a function we need troops to use this parenthesis.
OK, save it.
There you go.
I do have access to Rick, but the private variable, that was not the intent.
The intent was this variable cannot be accessed outside the class and this is outside the class directly.
OK, so we can manipulate.
So let me show this one to you, and we are done with this part.
So, Rick, dot my name and they should throw us an error.
Private field.
My name must be declared in on enclosing class.
Very good.
So we can't actually access this one.
Now this -- throws error.
So there you go.
We use private class where we will when we want to restrict a few variables, it can be a few variables
for internal usage only so we can add only hash before the variable and that will make a private and
can be accessed.
It cannot be accessed outside this class, but it can be accessed and not manipulated, can be accessed
by the methods here.
OK, there you go.
So these get details will bring out the output because this is not direct access.
It's accessing.
We are accessing the variable through the object.
Through the method.
Right.
So save it here.
Yeah.
Everything goes back to normal.
Nice.
Now let's talk about another awesome feature in iOS 11, and that is called Promis.
All settled.
Right.
So this is the new feature and it's very, very useful in order to explain you these few feature, I
need to create at least two promises.
Right.
Let me just do this.
I think it was number five, so promise that all settled.
Very good.
Now I'm going to create cost Promis one, and this will be new promise.
Remember, each and every promise has access to response and reject or resolve and reject that response.
And inside, I'm going to create a set time out and it will this set time out?
It will say response and this will be success.
Very good in the time out will be let's put 2000 milliseconds or that is two seconds, right?
So this is the first promise.
Now, let's create a second promise by copying this and pasting it here.
Just change this to two.
And instead of resolving let's reject this promise and say your field, OK?
And let's do this after ten thousand milliseconds.
This should be after 10 seconds.
Nice.
So.
What is promised that all?
Settled means so the problem that all settlement receives honorary it is uncute in promise, promise
felt good.
So this promise that also will receive honorary with the status object of every promises.
So here we do have two promises in this.
If I do promise that all settled in each side, it will receive an array of the two promises that I
have with the comma separated with the comma.
Now, oops, that should be too.
And so we can use that then.
Now why do you have these two here.
I don't need these two.
Brackets, right?
So promise that all settled, it will receive an array of the two promises with the status object of
every promise that we pass here.
So we passed two promises.
There will be two status objects.
So what I can do, I can change this with then and I will say data.
I can console lock.
The data now, because I've said this, when I save it, I've said this to 10 seconds, it will wait
a little bit longer until you see the result on the other side.
OK, let's wait for 10 seconds.
Maybe it was too long, but yeah, now the second promise is longer.
That's why we are waiting.
But it waits until all of the promises are settled and it gives us an array.
See here on a rate.
Let's see.
So in this array we do have the status fulfilled with the value of success and a status.
We reject it and reason it's failed.
Right.
So it will wait until all of the promise are settled and then it will give us an array with the final
data that we condoling consolingly right in here when the problem is that all we can pass multiple promises
here as an array, and this will have the status object of every promise that has passed.
So here is actually just sending the status that is failed.
And the reason in here we are sending the resolved or fulfilled with the value of success.
Now, you know, I promise that all and this is one of the feature that is helping us when we are dealing
with multiple promises.
Right.
In this promises we use promise that all because we want to use on the promises that are dependent on
each other so that I haven't mentioned.
But that was the thing that I should mention in the beginning.
So these two promises should be dependent on each other.
So here we can use promises that will settle and we can pass is an array with the status object of every
promise that we are passing.
And it will wait here of 10 seconds.
We can do a little bit less.
Let's make it for five seconds.
Save it and it will wait five seconds until each and every promise is resolved or settled, then when
it's done, it will give us the data back and it will give us an array with the final data.
OK, so that is a promise that all.
So let's do another one, and this is called Global Dis, so in JavaScript we generally use the window
object.
Remember we used a window object.
So if I cause a lot.
There I get the window, but now we have a global object and global disorder, so in JavaScript we generally
use the window.
But if we use no JS or other platform, the window will not work.
They have some different convention for accessing the global stuff.
And there it's called global.
So let's write this one here and say global this.
And you don't have to worry too much about this, right?
Global this.
Yeah.
Let's go back here, write it down.
Global this
now.
So this is nothing but.
How we are calling the global object, right?
So in JavaScript, we use window in Web workers, we use self so we will not work.
There is no as we use the global.
So with the global dis, accessing the global object will be the standard across all environments.
So that's what they're pushing.
So they want to have a standard across each and every environment.
Doesn't matter if we're using Noguez or what workers or whatever we use.
So now global, this will work.
So it works both in window and non window context.
So you can have access to this global object and we can have access to these global object the same
way in our JavaScript ecosystem.
Right.
We don't have any issues now how we can test if this is working?
Well, we need to check if this global object is there in one chat.
One thing that we can do is we can say Konza log.
To global, this should be equal to the window and this, ladies and gentlemen, should return us back.
True.
So now we are making sure that we can use global object and its exist now with the new features.
Oh, after a couple of seconds, we have we have the promise back.
That's why that change.
Right.
Even it will in note.
So this will not work here.
Now if you use in worker.
We're just going to say global, this will be equal to self, right?
And in note, this will be global.
This will be equal to global.
Right in here, it's equal to window because we are using our window object.
So that is pretty much it about the.
That is pretty much about the global debt, so if you want, you can try in all of these three environments,
but if you don't, that's that's up to you.
So you need to know that we have access to global this now.
And it's getting true when we see equal to the window.
And this is done because we want to have the same to use the same environment in every every environment
there.
Right.
OK.
And there you go, we have covered a lot of things here, we have covered six there, a couple of more
and I hope this was interesting.
Some of these are not logical for you guys will probably never use them.
But, yeah, get used to this.
Call this an operator.
That one was good and optional.
Chaining private class names.
Yeah.
This problem.
Is that all settled.
Yep.
For checking if the data that comes from all of the promises.
Right.
And global this now you just know that there is a global dis.
Yeah.
Object there.
So thank you very much and I will see you in the next one.