As you remember at the beginning of our course, we said that almost everything is an object in JavaScript.
It means that we refer one of the most important part of JavaScript.
So what is an object object grouped together as a set of variables and functions to create a model of
something you would recognize from the real world?
In JavaScript, objects are represented as collections of a name value pairs.
It is a simple and efficient way to collect variables and functions together.
Objects can have properties and methods, properties can be primitive data types like strings, numbers,
booleans or even arrays and object itself.
As for the methods, they are functions which are passed inside the objects in order to perform a specific
task in order to demonstrate it clearer.
Imagine that in real life, objects can be compared to person which has first name, last name, age,
profession, height, and all of these components can describe the person like as properties of objects.
And the same way we can compare the behavior of the person like speak, run, work, sing, read to
methods of the objects.
As it was in case of a race, we can create objects with different methods.
I hope that you remember what I'm talking about.
These two different ways are literal notation, which is commonly used and constructed notation with
keyword new.
OK, let's create an object using second method, which is a constructed notation writes variable person
equals to new object.
Let's see what we got in Castle, right, Castle, that luck person.
You see that we have an article about this, it means that we have created an empty object because the
curly braces always represent an object in order to add the properties to that empty object.
You can do it using that so.
Right person that first name.
Equals to John.
That is also operator, like other operators, for example, arithmetical compris and logical that you
already know that is called as member access operator.
And you can look at operator Prestons table where you will find that it has the highest Prestons number
after the grouping operator, which is parentheses and associativity as left-to-right.
So we can use that operator to create access or dynamically change the value of the property in object.
Let's add another property to our personal object, but in this case, use another method where we use
square brackets as the operator and inside them the property, which should be placed within quotes,
right person, then open square brackets and within quotes.
Right.
Last name.
Which equals to Smith.
Reload and you see that we have added another property to our object, but in this case using a different
type of operator.
All right, let's look at the operator president table, you can find brackets after dot operator,
they have the same person, this number and the same associativity.
In order to output the specified property of an object, we have to right here cancel that log person
Dot.
First name.
And that cost a lot like.
Person, use your different syntax right in square brackets.
Last night.
Reload and you see the properties in council separately using both operators, we get the same results,
but using that operator is more popular and it's commonly used.
However, both methods have their advantages and disadvantages.
Let's add another property to person, let's say job right to it in square brackets.
And then assigned to the value instructor.
Reload and we have another property here, job with this fellow instructor.
OK, now create the variable, call its job and assign value profession.
So here, Brackett's Syntex approach allows us to use variable in order to change property, name of
person object.
So if we write your variable name job.
Then we will get the new property profession, which is actually the value of variable job.
Let's try to do the same with the dot operator, create another variable and assign the value of first
name, which is property of personal object.
That change first came into name.
And see what happens.
Instead of first time, we got Knabe, which is just a new property, and also you can notice that here
we have undefined because the property first name is no longer available.
So when we wrote name after dot operator, JavaScript engine didn't link it to variable name, which
was created up here.
So this is one of the distinctions between dot operator and Brackett's.
OK, if we want to change the value of property, we can do it dynamically as it was in case of iRace.
Just simply right person, not name equals to Bob.
Reload and you see that John is changed into pop.
All right, let's get rid of these codes.
We don't need them anymore and create new properties, right?
Again, person that Faustine.
Equals to John.
That person, that last name.
Equals to Smith.
As you remember, we said at the beginning of this lecture that we can add as the property and object
itself.
And now let's do it at first, create new object.
Right person, Dodgson.
Equals to new object.
Let's run it in council and see what we have cost of that person.
So you see that there is created new empty objects inside the person object, and in order to add new
properties to it, we can use again dot operator.
At first, we need to exercise on this sun object is the right person, the sun and then add new property,
use again dot operator and then write property name.
That aside, the value ethnic.
Let's add another property, so right person.
Not, son, that age equals to five.
Reload and you have some object with its properties named Nick and Five.
All right, in this video, we have used object construction location in order to demonstrate better
the things we have just discussed.
In the next video, you will learn about object, little notation and also the methods of objects.
Let's move on.