Understanding Objects in JavaScript

Learning web development in public. Writing simple, real-world explanations about web development concepts. Helping beginners understand why things work, not just how.
Search for a command to run...

Learning web development in public. Writing simple, real-world explanations about web development concepts. Helping beginners understand why things work, not just how.
No comments yet. Be the first to comment.
Every day, millions of users upload photos, videos, stories, and reels to Instagram. From a user's perspective, the process appears simple: select media, apply filters, add a caption, and tap "Post."
Building Offline-First Messaging Apps: How Messages Work Without Internet Modern messaging applications have transformed the way people communicate. Whether it's chatting with friends, collaborating w
In this article we'll explore about the Expo Router and React Navigation and answer which one to use in 2026. If you build mobile apps using React Native, one thing becomes obvious very quickly: Navig

Modern mobile apps are no longer just a collection of screens connected together. Apps like Instagram, WhatsApp, Uber, and Netflix operate at massive scale with millions of users, real time systems, o
In this article we'll be exploring react.js and the things of react.js that makes it popular and stand out among other libraries ( no fight over library vs framework ). We'll go through: What problem

Shkaai
68 posts
When learning JavaScript, variables help us store individual pieces of data such as numbers, strings, or boolean values. However, real-world data is often more complex and usually consists of multiple related pieces of information. This is where objects become useful.
An object in JavaScript is a data structure used to store multiple related values in a single variable. These values are stored as key–value pairs.
Think of an object like a real-world entity that has different properties.
For example, if we want to represent a person in our program, we might want to store information like their name, age, and city. Instead of creating multiple variables, we can group them together using an object.
const person = {
name: "Sam",
age: 29,
city: "Haryana"
};
In this example:
name, age, and city are keys (properties)
"Sam", 29, and "Haryana" are their values
Objects help us organize related data together, making our code easier to manage and understand.
Objects are created using curly braces {}.
const person = {
name: "Sam",
age: 29,
city: "Haryana"
};
Each property inside the object is written as:
key: value
Multiple properties are separated using commas.
We can access object properties in two ways.
The most common way to access object properties is using dot notation.
console.log(person.name);
console.log(person.age);
Output:
sam
29
Another way to access properties is bracket notation.
console.log(person["city"]);
Output:
Haryana
Bracket notation is useful when the property name is dynamic or stored in a variable.
We can update an object's property by assigning a new value.
person.age = 23;
console.log(person.age);
Output:
23
Objects allow their properties to be updated easily.
We can also add new properties to an object.
person.country = "India";
console.log(person);
Now the object becomes:
{
name: "Sam",
age: 23,
city: "Haryana",
country: "India"
}
If we want to remove a property from an object, we can use the delete keyword.
delete person.city;
console.log(person);
Now the city property will be removed.
Sometimes we want to access all properties of an object. We can use a for...in loop to iterate through the keys.
for (let key in person) {
console.log(key, person[key]);
}
Output:
name Sam
age 29
country India
Here:
key represents the property name
person[key] gives the value of that property
Example of an array:
const fruits = ["apple", "banana", "mango"];
Example of an object:
const person = {
name: "Sam",
age: 29
};
Arrays are used for lists of data, while objects are used for structured data with properties.
As a beginner you should start by making object on your own like this:
Create an object representing a student.
Create an object called student.
Add properties:
name
age
course
Update one property.
Print all keys and values using a loop.
Example starter code:
const student = {
name: "Rahul",
age: 20,
course: "Computer Science"
};
student.age = 21;
for (let key in student) {
console.log(key, student[key]);
}
Objects are one of the most important data structures in JavaScript. They allow us to store and organize related data using key–value pairs. By learning how to create objects, access properties, update them, and loop through them, we can represent real-world data more effectively in our programs.
Understanding objects is an essential step toward writing more structured and maintainable JavaScript code.