DEV Community

Cover image for Objects in JavaScript.
Keshav Jindal
Keshav Jindal

Posted on • Edited on

2

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"]

Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay