WEBVTT

00:00.750 --> 00:05.490
One of the most important data structures in javascript are objects.

00:05.850 --> 00:10.410
This is like those movies where when you reach the end of the movie there are some tweaks in the plot

00:10.500 --> 00:14.190
and everything ended up being not like you thought at first.

00:14.380 --> 00:20.340
Well this is something like that I'm gonna tell you now that most things we've looked into are objects

00:20.340 --> 00:23.100
at the end of the day so strings are objects.

00:23.100 --> 00:25.670
Functions are objects.

00:25.830 --> 00:32.010
The only thing that we've seen that are not objects are the numbers and the boolean variables.

00:32.190 --> 00:38.890
The way that we've created them are primitive variables which are not objects.

00:39.410 --> 00:42.050
But you can also create them in a way that are objects.

00:42.060 --> 00:48.150
We're not looking to that because I don't really see the point where you're not going to use them as

00:48.150 --> 00:50.720
objects very often.

00:51.150 --> 00:54.140
So arrays strings are objects.

00:54.390 --> 00:59.040
And in this particular lesson we're going to cover the basics of objects we're going to learn how to

00:59.040 --> 01:03.560
create them how to access their properties and how to create methods.

01:03.570 --> 01:07.170
There are two ways of creating objects and they're equivalent.

01:07.210 --> 01:14.570
And to create an object called a set one of them is by typing new object and brackets.

01:14.580 --> 01:19.620
So that's how you can create a new object and we'll put that

01:23.170 --> 01:25.090
that's just an empty object.

01:25.090 --> 01:31.600
Another equivalent manner of creating an object is like this.

01:31.630 --> 01:32.740
That's an empty object.

01:32.830 --> 01:38.480
Curly brackets for real of the page you get the exact same thing.

01:39.070 --> 01:46.360
We can we can have properties to this object so for instance I can give it a name

01:49.280 --> 01:51.610
I can give it a certain age

01:54.400 --> 01:54.970
city

01:58.230 --> 02:02.350
let's let's look at that and the council now object.

02:02.370 --> 02:05.140
See what it's looking like.

02:05.730 --> 02:12.630
We get it always we always get a label like a property name on a value.

02:12.810 --> 02:13.970
It's always like that.

02:14.130 --> 02:20.160
And you can also have objects have some of these properties can also be other objects or they can be

02:20.190 --> 02:23.730
traced and we could have something like this.

02:27.640 --> 02:30.370
Different friends of this person.

02:31.580 --> 02:40.110
So you can use objects to represent basically everything all data all data sets.

02:40.700 --> 02:48.290
And this way of working with with objects or even database engines does that work in this way where

02:48.290 --> 02:52.470
you can store your information this manner.

02:53.100 --> 03:00.710
So another besides besides giving them properties like this I just mentioned a few minutes back that

03:00.740 --> 03:03.010
functions are objects too.

03:03.020 --> 03:04.620
So we could create.

03:05.330 --> 03:07.190
We could give it a property.

03:07.190 --> 03:08.930
It's actually a function.

03:09.080 --> 03:12.810
And one way of doing that is like this.

03:12.880 --> 03:14.290
So some method.

03:15.240 --> 03:24.050
And that's just going to be a function and this function is going to say take two values and return

03:24.050 --> 03:27.220
the sum of those values.

03:28.160 --> 03:36.560
Now if I relive the page we have our object in here being shown in the console there's a friend's name

03:36.560 --> 03:46.770
some method and then we have a function and we could also use that execute that method by doing but

03:47.450 --> 03:50.470
just calling it the same in the same way.

03:50.550 --> 03:54.280
We've called methods before like console log.

03:54.320 --> 04:00.050
It's actually being way actually calling a method call log of an object called called console which

04:00.050 --> 04:03.000
is available for us to use in the web browser.

04:03.440 --> 04:12.950
So see I'm calling a dot some method or some method takes two numbers and this will give us the number

04:12.950 --> 04:16.440
three in our console.

04:16.610 --> 04:24.410
So most things in javascript are objects you need to get cozy with objects to understand them well and

04:24.500 --> 04:26.490
see learn how they work.

04:26.510 --> 04:33.220
Create a couple of objects to represent say a person or a CD.

04:33.260 --> 04:35.530
Be familiar with accessing the properties.

04:35.690 --> 04:42.830
So you always access the properties by using the dot and you can do that to either write that property

04:42.920 --> 04:46.540
or modify it if it if it had already been created before.

04:46.700 --> 04:56.690
Or you can use that just to read for example and see how I can just get the CD by doing a dot city and

04:56.690 --> 04:58.750
something that I was almost missing.

04:58.760 --> 05:04.040
It's another way of fixing the problem accessing a property is by doing it in the same way that we did

05:04.040 --> 05:12.080
with our race which is with square brackets and then inside the square brackets you use quotes and you

05:12.080 --> 05:15.050
referred to the name of that property.

05:15.080 --> 05:21.050
So these are two equivalent ways of accessing a property whether it's for reading the property value

05:21.050 --> 05:27.210
of that property or whether it's for modifying for writing that the value of that property.
