In previous video, we have learned about what an object is and we have used constructor notation method
to create that, but as I remember, we said that it's not the preferred method in real life.
There is a better, more convenient and much quicker way to create objects.
And it's called literal notation.
So as you know, when we use constructor notation, we write your variable person equals to new object.
Let's run it again in Castle and see how it works.
So we have an object which is represented with curly braces and those Calabrese is exactly what we need
in little notation method.
Let's the this new object and instead of it.
Right.
Just curly braces.
Reload and you see, nothing is changed because we have just created new empty object again, but using
a different way calibrates this is not an operator like DOT or square brackets.
Operator when JavaScript engine is empty color Brice's, it knows that it has to create an object in
order to add properties to person object.
We have just the right property names inside curly braces that column and the value reload.
So we have a first name, John.
If we want to add more properties, we do it in the same way.
But you need to know that we have to separate them by commas.
Let's add other properties.
Last name Smith and age 27.
All right.
For better readability like it was in case of iRace, let's organize our code.
It's more convenient.
Better to read and prefer to wait when we work with objects in case of constructor method to get the
same result we needed to write variable person one equals two new object.
Then for adding each property we needed to right every time person one dot first name equals two bob.
That person won that last name equals the dough, and eventually the result is same.
So you can see how convenient this literal notation method, the code is clearer, it's easy to read
and we type less.
But regardless of that, you're able to add properties and methods using dot our brackets operator in
case of literal notation method as well.
So I recommend to use literal notation.
All right, let's remove this code and now create inside person another object.
We can do it in the exact same way we need to use curly braces.
So right doctor with its properties name as memory and age five.
Reload and again, we have a new object inside person object to access on the values of the properties
is the same as it was in constructor notation method.
So let's get the value from that through object.
Let's duplicate that log in order to avoid typing the same each time and add Dr. Dot name.
Reload and we have merit.
All right, let's talk about functions in object, which are called methods in order to pass the function
inside an object.
At first we have to write method name and we have to do it in the same way as it was for the properties.
So write my function then assigned to it function.
We always use anonymous functions, which is a function without name.
We use anonymous functions here because we can call them using method names.
Let's see it right.
Cancel that log.
Hello World.
And then in order to call this method right person, that my function, because of that, we have consulate
log inside the function.
We do not need to write it again when we call this function, reload the page.
And here we have.
Hello, Walt.
All right.
Let's make our example more complex and use the properties inside the function.
But before that, let's pass some parameters to you.
For example, daughter name than father name.
And Dr. H
and then writing Castle, not a name plus.
Is a daughter of that place, your second parameter father's name, then again, some text, and she
is.
Then we need to your daughter age and finally years old.
All right, now past the arguments here and use the properties of person object as daughter name, we
should right here.
Person, dot, dot, dot name.
Then as the father name right person, that first name and as for the age of daughter, that's right,
person, dot, dot, dot, h
reload.
And we have Mary is a daughter of John, and she is five years old.
All right, we can pass new object as the arguments on the fly.
I mean, when we call the function for that, we need only one parameter because we are going to use
object as an argument.
Let's place here as a parameter part.
Then create an object on the fly, right?
That's her name.
As Jesse then father name.
Michael.
And as Dr. H.
Writes, you fight, as we already know, to get the values of the properties from the objects we need
to use dot operator.
So write to all the properties per dot.
So, again, we have passed a single parameter inside our method, then we passed on the fly and object
as an argument and used its property values revoked.
And we have Jesse is a daughter of Michael and she's five years old.
All right.
You already know much about objects, but because of that, JavaScript is an object based language.
We need to go deeper and learn advanced things regarding objects, and you will do it throughout the
course.
But for now, for the basic level, it's really excellent.
Let's go ahead.