Data Types in JavaScript : Object

Object is a collection of properties and actions/methods in JavaScript. Whatever types we have discussed before (string, number, boolean, undefined) are all primitive data types. Means they are not object and they don’t contain any methods. They just contain a single value.

Object is a structural data type. Using object you can store multiple values in form of properties. Also, you can define methods to perform action on object.

Example of Object

Suppose you want to define information of person, how would you? You cannot use primitive data types because to define person you need to store multiple values. So, in this case you will use object.

‎
let person = {
    FirstName : 'Bill',
    LastName : 'Gates'
}
console.log(person.FirstName + " " + person.LastName);
‎

In the above example you can see that we have defined person object. After equal to sign (=) in the curly bracket we have defined information of the person (FirstName & LastName).

In the console log we are just displaying information from object. To get information from object you just need to call objectreferencename.propertyname & you will get value of properties from that object.

Here is the output:

That’s it. It is very basic level of object knowledge. In the future articles we’ll deep dive in the object data type.

Categories js

Subscribe Now!

Subscribe Us For Latest Articles