Back to blog
JavaScript

Understanding Objects in JavaScript

May 10, 2026 2 min read

What Are Objects?

Objects store related data using:

key → value

pairs.

They help organize real-world entities.


Real-World Example

A person has:

  • Name

  • Age

  • City

Instead of separate variables:

const name = "Ali";
const age = 22;
const city = "Lucknow";

we group them into one object.


Creating an Object

const person = {
  name: "Ali",
  age: 22,
  city: "Lucknow"
};


Object Structure Visualization

Diagram: flowchart TD

Objects Are Key-Value Structures

KeyValue
name"Ali"
age22
city"Lucknow"

Accessing Properties

1. Dot Notation

console.log(person.name);
console.log(person.age);


Output

Ali
22


2. Bracket Notation

console.log(person["city"]);


Output

Lucknow


Dot vs Bracket Notation

MethodSyntax
Dot Notationperson.name
Bracket Notationperson["name"]

Updating Object Properties

person.age = 23;

console.log(person.age);


Output

23


Adding New Properties

person.country = "India";

console.log(person);


Output

{
  name: "Ali",
  age: 23,
  city: "Lucknow",
  country: "India"
}


Deleting Properties

delete person.city;

console.log(person);


Output

{
  name: "Ali",
  age: 23,
  country: "India"
}


Looping Through Object Keys

Use:

for...in


Example

const person = {
  name: "Ali",
  age: 22,
  city: "Lucknow"
};

for (let key in person) {
  console.log(key, person[key]);
}


Output

name Ali
age 22
city Lucknow


How Looping Works

Diagram: flowchart LR

Array vs Object

Array

Stores ordered values.

const fruits = ["apple", "banana"];

Accessed using indexes.


Object

Stores named values.

const person = {
  name: "Ali"
};

Accessed using keys.


Comparison Diagram

Diagram: flowchart TD

Array vs Object Table

FeatureArrayObject
StructureOrdered listKey-value pairs
AccessIndexKey
Best ForListsRelated properties

Practical Example

const car = {
  brand: "Toyota",
  model: "Camry",
  year: 2024
};

console.log(car.brand);

car.year = 2025;

console.log(car);


Assignment

Step 1: Create Student Object

const student = {
  name: "Sara",
  age: 20,
  course: "Computer Science"
};


Step 2: Update Property

student.age = 21;


Step 3: Loop Through Object

for (let key in student) {
  console.log(key, student[key]);
}


Common Beginner Mistakes

Forgetting Quotes in Bracket Notation

Incorrect:

person[name]

Correct:

person["name"]


Using Array Syntax for Objects

Incorrect:

person[0]

Objects use keys, not indexes.


Key Takeaways

ConceptSummary
ObjectCollection of key-value pairs
Dot Notationobject.key
Bracket Notationobject["key"]
Update PropertyAssign new value
Delete Propertydelete object.key
Loop Objectfor...in

Final Notes

Objects are one of the most important concepts in JavaScript because almost everything in JavaScript is built around objects.

Used heavily in:

  • APIs

  • React

  • Databases

  • Backend development

  • Frontend applications


0 Comments

Sign in to join the conversation

No comments yet. Be the first to comment!