DEV Community

Cover image for Objects in JavaScript.
Keshav Jindal
Keshav Jindal

Posted on • Updated on

Objects in JavaScript.

1. What are Objects
Objects are one of the datatype in JavaScript which is very useful as it can store multiple type of values like: string, Boolean, int, etc.
For example:

Image description

Properties  
book.name= Harry Potter         
book.color= Purple
book.size= A4
Enter fullscreen mode Exit fullscreen mode

2. Accessing the data
for example:

const person = {
  firstName: "John",
  lastName: "Doe",
  age: 50,
  eyeColor: "blue"
};
console.log(person.age);
console.log(person.eyecolor);
Enter fullscreen mode Exit fullscreen mode

Output:
50
blue
3. Object Methods
Object Methods can be accessed by using functions which are stored as properties in JavaScript.
Example:

const my_object = {
  firstName: "Ronn",
  lastName : "Doe",
  uid       : 9980,
  }
};
console.log(my_object)
Enter fullscreen mode Exit fullscreen mode

Output:
firstName: "Ronn",
lastName : "Doe",
uid : 9980,

4. Accessing Object Methods
Syntax:
object_name.property;
OR
object_name["property"]

Top comments (0)