WEBVTT

00:01.590 --> 00:07.150
As you remember at the beginning of our course, we said that almost everything is an object in JavaScript.

00:07.830 --> 00:12.510
It means that we refer one of the most important part of JavaScript.

00:13.020 --> 00:20.490
So what is an object object grouped together as a set of variables and functions to create a model of

00:20.490 --> 00:22.920
something you would recognize from the real world?

00:23.670 --> 00:27.900
In JavaScript, objects are represented as collections of a name value pairs.

00:29.130 --> 00:33.600
It is a simple and efficient way to collect variables and functions together.

00:34.660 --> 00:41.260
Objects can have properties and methods, properties can be primitive data types like strings, numbers,

00:41.260 --> 00:45.070
booleans or even arrays and object itself.

00:45.940 --> 00:52.150
As for the methods, they are functions which are passed inside the objects in order to perform a specific

00:52.150 --> 00:54.920
task in order to demonstrate it clearer.

00:54.970 --> 01:01.810
Imagine that in real life, objects can be compared to person which has first name, last name, age,

01:02.170 --> 01:09.130
profession, height, and all of these components can describe the person like as properties of objects.

01:10.250 --> 01:19.760
And the same way we can compare the behavior of the person like speak, run, work, sing, read to

01:19.760 --> 01:21.050
methods of the objects.

01:22.280 --> 01:26.280
As it was in case of a race, we can create objects with different methods.

01:26.660 --> 01:28.850
I hope that you remember what I'm talking about.

01:29.360 --> 01:34.970
These two different ways are literal notation, which is commonly used and constructed notation with

01:34.970 --> 01:35.840
keyword new.

01:37.400 --> 01:44.630
OK, let's create an object using second method, which is a constructed notation writes variable person

01:45.410 --> 01:47.120
equals to new object.

01:50.280 --> 01:54.210
Let's see what we got in Castle, right, Castle, that luck person.

01:57.980 --> 02:04.850
You see that we have an article about this, it means that we have created an empty object because the

02:04.850 --> 02:09.830
curly braces always represent an object in order to add the properties to that empty object.

02:10.310 --> 02:13.220
You can do it using that so.

02:13.250 --> 02:15.620
Right person that first name.

02:17.790 --> 02:18.780
Equals to John.

02:21.670 --> 02:28.060
That is also operator, like other operators, for example, arithmetical compris and logical that you

02:28.060 --> 02:31.650
already know that is called as member access operator.

02:32.050 --> 02:39.490
And you can look at operator Prestons table where you will find that it has the highest Prestons number

02:39.490 --> 02:45.550
after the grouping operator, which is parentheses and associativity as left-to-right.

02:46.580 --> 02:53.720
So we can use that operator to create access or dynamically change the value of the property in object.

02:55.270 --> 03:01.450
Let's add another property to our personal object, but in this case, use another method where we use

03:01.450 --> 03:07.780
square brackets as the operator and inside them the property, which should be placed within quotes,

03:08.560 --> 03:13.480
right person, then open square brackets and within quotes.

03:13.480 --> 03:13.830
Right.

03:14.080 --> 03:14.800
Last name.

03:16.840 --> 03:18.580
Which equals to Smith.

03:21.170 --> 03:28.160
Reload and you see that we have added another property to our object, but in this case using a different

03:28.160 --> 03:29.210
type of operator.

03:30.190 --> 03:37.890
All right, let's look at the operator president table, you can find brackets after dot operator,

03:38.320 --> 03:41.920
they have the same person, this number and the same associativity.

03:43.720 --> 03:51.610
In order to output the specified property of an object, we have to right here cancel that log person

03:51.610 --> 03:52.030
Dot.

03:53.660 --> 03:54.380
First name.

03:56.900 --> 03:58.490
And that cost a lot like.

04:00.860 --> 04:06.710
Person, use your different syntax right in square brackets.

04:07.900 --> 04:08.440
Last night.

04:10.780 --> 04:18.220
Reload and you see the properties in council separately using both operators, we get the same results,

04:18.760 --> 04:22.420
but using that operator is more popular and it's commonly used.

04:23.170 --> 04:26.510
However, both methods have their advantages and disadvantages.

04:27.370 --> 04:35.170
Let's add another property to person, let's say job right to it in square brackets.

04:36.200 --> 04:38.510
And then assigned to the value instructor.

04:40.820 --> 04:45.350
Reload and we have another property here, job with this fellow instructor.

04:46.500 --> 04:52.980
OK, now create the variable, call its job and assign value profession.

04:55.750 --> 05:02.620
So here, Brackett's Syntex approach allows us to use variable in order to change property, name of

05:02.770 --> 05:03.790
person object.

05:04.780 --> 05:08.050
So if we write your variable name job.

05:10.010 --> 05:16.820
Then we will get the new property profession, which is actually the value of variable job.

05:18.980 --> 05:24.980
Let's try to do the same with the dot operator, create another variable and assign the value of first

05:24.980 --> 05:28.040
name, which is property of personal object.

05:30.710 --> 05:33.980
That change first came into name.

05:35.670 --> 05:36.990
And see what happens.

05:38.950 --> 05:45.930
Instead of first time, we got Knabe, which is just a new property, and also you can notice that here

05:45.970 --> 05:50.630
we have undefined because the property first name is no longer available.

05:51.490 --> 05:58.630
So when we wrote name after dot operator, JavaScript engine didn't link it to variable name, which

05:58.630 --> 05:59.780
was created up here.

06:00.610 --> 06:05.320
So this is one of the distinctions between dot operator and Brackett's.

06:07.170 --> 06:13.450
OK, if we want to change the value of property, we can do it dynamically as it was in case of iRace.

06:14.820 --> 06:19.770
Just simply right person, not name equals to Bob.

06:21.060 --> 06:24.900
Reload and you see that John is changed into pop.

06:26.040 --> 06:28.280
All right, let's get rid of these codes.

06:28.290 --> 06:32.250
We don't need them anymore and create new properties, right?

06:32.250 --> 06:33.930
Again, person that Faustine.

06:35.460 --> 06:36.570
Equals to John.

06:37.770 --> 06:39.630
That person, that last name.

06:42.260 --> 06:43.280
Equals to Smith.

06:45.480 --> 06:51.420
As you remember, we said at the beginning of this lecture that we can add as the property and object

06:51.420 --> 06:51.840
itself.

06:52.230 --> 06:54.810
And now let's do it at first, create new object.

06:56.050 --> 06:57.520
Right person, Dodgson.

06:59.020 --> 07:00.970
Equals to new object.

07:03.650 --> 07:08.270
Let's run it in council and see what we have cost of that person.

07:12.040 --> 07:18.940
So you see that there is created new empty objects inside the person object, and in order to add new

07:18.940 --> 07:21.730
properties to it, we can use again dot operator.

07:22.720 --> 07:29.440
At first, we need to exercise on this sun object is the right person, the sun and then add new property,

07:29.590 --> 07:33.280
use again dot operator and then write property name.

07:34.700 --> 07:36.620
That aside, the value ethnic.

07:38.710 --> 07:42.010
Let's add another property, so right person.

07:43.070 --> 07:48.250
Not, son, that age equals to five.

07:49.380 --> 07:55.980
Reload and you have some object with its properties named Nick and Five.

07:57.550 --> 08:03.790
All right, in this video, we have used object construction location in order to demonstrate better

08:03.820 --> 08:05.350
the things we have just discussed.

08:05.860 --> 08:11.450
In the next video, you will learn about object, little notation and also the methods of objects.

08:12.250 --> 08:12.880
Let's move on.
