We have already talked about that almost everything is an object in JavaScript.
So what does it mean when we say almost you already know that there are two types of data in JavaScript,
primitives like strings, numbers, booleans, undefined and no and non primitives like arrays, functions,
objects, dates and etc..
So when we say that everything is an object in JavaScript, it means that everything except primitive
data is an object.
All right, let's go to Brackett's and using some practical examples of that fact, at first I'm going
to use an example regarding a race.
So let's create a simple array right of equals and pass are the numbers as items one, two and three.
As we know, we can add another item on the fly using the following method.
We need to write a rate that inside the square brackets, we need to indicate the index number in this
case three, because we're going to add new item as the fourth item and then equals four.
Let's check it in Castle, right, Castle, that look right.
Reload.
So you see that new item as a fourth member is added to the array.
OK, generally, when we deal with objects and want to add properties and methods to them for that,
we can use DOT or notation in order to prove that array is an object.
I'm going to add a new item to it as a property.
So right away, dot prop.
Equals two.
Hello.
Reload.
And you can see that hello is a part of the al, right, and it looks like as a prop., it's not added
as usual, array item.
If we drop down it, you will see that the length prop. indicates that this array has four items and
not five.
If we want to access on hello, we cannot do it using index numbers.
We need to use dot notation or notation.
So if we write in council a right dot prop.
Then we will get hello.
So this little example proves that a right is an object.
All right.
Now, let's move on and talk about functions, functions like arrays are objects you can attach to it
as a property, primitive objects or another function.
But the main difference between functions and objects is that functions are invaluable.
In order to execute the code, we need to call them.
Let's see some examples at first.
Let's get rid of these codes and write function A.
And then he said the cool braces, right?
Castle looked like a lot.
So here we have a simple function and now I'm going to attach to it a prop. at first as primitive,
and in this case, let's use bracket notation, right aid, then open square brackets and right prop
as a prop. within single quotes and then equals to high.
OK, now let's add object as a property, right, a dot object.
And create a simple object right here, property great with the value.
Hey.
And also, I'm going to attach to function a another function as a method, so write a dot my function.
Equals right here, anonymous function.
And then inside the school braces, I'd consider log.
Although.
Reload, you see that the function is created on global level, so let's check a window object right
window in Castle.
Then dropped down it.
So here we have the function eight, if we drop down it as well, you can see that all of this stuff
which we have written is added to function A my function is attached to it as a method.
Also, we have here object as a property and then we have another property as a primitive high.
So when we attached them to the function eight, they became the parts of it again, as it was in case
of arrays.
It proves that functions are objects as well.
All right.
I think that it was interesting to know such stuff is very important in other programming languages,
it's not possible to act arrays and functions like objects, but in JavaScript it's possible because,
as we said, they are special type of objects.
Objects and functions have very close connection to each other, especially when we deal with advanced
JavaScript and will be able to see definitely incoming videos.
Let's move on.