WEBVTT

00:01.260 --> 00:05.410
We have already talked about that almost everything is an object in JavaScript.

00:06.240 --> 00:12.720
So what does it mean when we say almost you already know that there are two types of data in JavaScript,

00:13.440 --> 00:22.980
primitives like strings, numbers, booleans, undefined and no and non primitives like arrays, functions,

00:22.980 --> 00:25.530
objects, dates and etc..

00:26.310 --> 00:32.010
So when we say that everything is an object in JavaScript, it means that everything except primitive

00:32.010 --> 00:33.360
data is an object.

00:34.600 --> 00:41.410
All right, let's go to Brackett's and using some practical examples of that fact, at first I'm going

00:41.410 --> 00:43.990
to use an example regarding a race.

00:44.350 --> 00:54.190
So let's create a simple array right of equals and pass are the numbers as items one, two and three.

00:55.210 --> 00:59.490
As we know, we can add another item on the fly using the following method.

01:00.040 --> 01:07.780
We need to write a rate that inside the square brackets, we need to indicate the index number in this

01:07.780 --> 01:15.310
case three, because we're going to add new item as the fourth item and then equals four.

01:18.220 --> 01:21.940
Let's check it in Castle, right, Castle, that look right.

01:25.230 --> 01:25.790
Reload.

01:27.120 --> 01:31.140
So you see that new item as a fourth member is added to the array.

01:32.130 --> 01:39.630
OK, generally, when we deal with objects and want to add properties and methods to them for that,

01:39.630 --> 01:45.950
we can use DOT or notation in order to prove that array is an object.

01:45.990 --> 01:49.310
I'm going to add a new item to it as a property.

01:50.040 --> 01:54.090
So right away, dot prop.

01:56.650 --> 01:57.530
Equals two.

01:57.600 --> 01:58.000
Hello.

02:00.580 --> 02:01.120
Reload.

02:02.690 --> 02:09.740
And you can see that hello is a part of the al, right, and it looks like as a prop., it's not added

02:09.740 --> 02:11.590
as usual, array item.

02:12.230 --> 02:19.490
If we drop down it, you will see that the length prop. indicates that this array has four items and

02:19.490 --> 02:20.270
not five.

02:22.430 --> 02:27.120
If we want to access on hello, we cannot do it using index numbers.

02:27.500 --> 02:30.650
We need to use dot notation or notation.

02:31.100 --> 02:35.330
So if we write in council a right dot prop.

02:38.040 --> 02:39.510
Then we will get hello.

02:41.900 --> 02:45.410
So this little example proves that a right is an object.

02:47.200 --> 02:47.680
All right.

02:49.290 --> 02:56.370
Now, let's move on and talk about functions, functions like arrays are objects you can attach to it

02:56.370 --> 03:00.420
as a property, primitive objects or another function.

03:01.080 --> 03:05.310
But the main difference between functions and objects is that functions are invaluable.

03:05.880 --> 03:08.340
In order to execute the code, we need to call them.

03:09.600 --> 03:11.310
Let's see some examples at first.

03:11.710 --> 03:16.920
Let's get rid of these codes and write function A.

03:20.230 --> 03:22.370
And then he said the cool braces, right?

03:22.510 --> 03:24.280
Castle looked like a lot.

03:28.950 --> 03:35.840
So here we have a simple function and now I'm going to attach to it a prop. at first as primitive,

03:36.480 --> 03:45.780
and in this case, let's use bracket notation, right aid, then open square brackets and right prop

03:46.230 --> 03:51.540
as a prop. within single quotes and then equals to high.

03:55.250 --> 04:01.730
OK, now let's add object as a property, right, a dot object.

04:03.430 --> 04:09.280
And create a simple object right here, property great with the value.

04:09.320 --> 04:09.700
Hey.

04:14.320 --> 04:22.900
And also, I'm going to attach to function a another function as a method, so write a dot my function.

04:24.540 --> 04:27.120
Equals right here, anonymous function.

04:29.580 --> 04:33.570
And then inside the school braces, I'd consider log.

04:35.840 --> 04:36.260
Although.

04:39.850 --> 04:47.320
Reload, you see that the function is created on global level, so let's check a window object right

04:47.320 --> 04:48.430
window in Castle.

04:51.100 --> 04:52.660
Then dropped down it.

04:55.000 --> 05:02.530
So here we have the function eight, if we drop down it as well, you can see that all of this stuff

05:03.790 --> 05:10.750
which we have written is added to function A my function is attached to it as a method.

05:11.890 --> 05:20.140
Also, we have here object as a property and then we have another property as a primitive high.

05:21.730 --> 05:29.920
So when we attached them to the function eight, they became the parts of it again, as it was in case

05:29.920 --> 05:30.520
of arrays.

05:30.910 --> 05:33.670
It proves that functions are objects as well.

05:35.230 --> 05:35.770
All right.

05:36.810 --> 05:43.730
I think that it was interesting to know such stuff is very important in other programming languages,

05:43.740 --> 05:49.440
it's not possible to act arrays and functions like objects, but in JavaScript it's possible because,

05:49.440 --> 05:51.750
as we said, they are special type of objects.

05:52.830 --> 05:58.110
Objects and functions have very close connection to each other, especially when we deal with advanced

05:58.110 --> 06:02.020
JavaScript and will be able to see definitely incoming videos.

06:02.640 --> 06:03.240
Let's move on.
