Previous tutorial we talked about primitive type of data or primitive type variables, but in this tutorial we are going to talk about something else which is Reference Type variables. And Reference Type variables are a little bit complicated than primitive type variables because they contain many variables at the same time, and we have basically three types of reference type variables. The first one is objects, the second type is functions. The third one is arrays. The one that we are going to talk about in this video is objects. What objects are they are anything around you think, think about it have anything that has properties.
So for example, a car has properties It has an engine it has speed color, many, many properties. Another example is a house, a house has a color has doors has windows has many other properties. Another example is a person, a person has a name as an age, and also has a job title. But the question is, why would we use objects? And why not? We just use simple variables?
The answer is that it would be very difficult when you create real applications to use just variables because in real applications, you would need many, many variables. And it would be very difficult to have many variables in your program. Instead, you would use just objects which is going to make your life much easier. And as time goes by and as you get more experience, you will know how important objects are. So let's now take a example here, we have here three variables name, age, and job name most age 25 job software engineer. And instead of just creating this, these three variables, we can just compare, we can just combine all of these in one variable called Pearson.
So to create an object, you just type four and then person equals two curly braces. And then inside these curly braces, you would type name and then colon, I think coats and then the name which is most, I think, comma, and then H, and then 25, and then comma, and then job and then colon, and then the job which is soft, where engineer, engineer and don't forget the semicolon at the So this is an object. As you can see, this is an object. A person has these properties, name, age, and job. And of course, person could have more much more than just these properties, maybe gender, maybe other things as well. So how can we print these on the log, it's so simple, just use the console, and then dot log, and pass that person inside person, and colon.
And let's now a semicolon. And let's now save and run. And as you can see here in the console log, we have the name, the age and the job. But what if we want to get only one, a property from this object? It's so simple. There are actually two ways to call a property from an object.
So if we want to get the name we just use person dot name. So for example, for me equals to person, dot name and semicolon. And then we pass here the name. And what we should get after that is the name. And as you can see, we have the name, which is the which is most, if we want the age, I'm going to change this to age. And here as well, I'm going to call the age, save and also here age, Save and Run.
And as you can see, we get the age The same goes for the job. And of course, we can do that immediately inside the console dot log. So I'm going to use person, person dot age and save and run and as you can see the age has been printed here. And the other way to call properties from an object is to use square brackets. So instead of the dot notation, I am going to change these two square brackets and inside I'm going to pass age If I save and run, and of course I should here past age, Save and Run. As you can see, we have here the age 25.
So these are the two ways to call properties form an object, but the one that is commonly used is the dot notation, which is person dot H dot h. And of course, you can create object objects of anything, you can create an object as I told you, you have a car, a car object, and then inside you can add the module the name, the engine type, anything the color, and you can, of course creating an object of anything. And I want you to practice this because objects are very powerful and important in any programming language and in JavaScript in specific