What is an Object in JavaScript?
An object in JavaScript is a collection of data stored in key–value pairs. It helps us group related information together in a structured way.
Example:
let person = {
name: "Arun",
age: 22,
city: "Chennai"
};
Here, name, age, and city are keys, and their corresponding values store information about the person.
Why Are Objects Important?
Without objects, we would store related data in separate variables, making our code messy and harder to manage.
Objects help us:
- Organize data efficiently
- Represent real-world entities
- Write clean and maintainable code
Why Do We Need Objects?
Objects are essential because they allow developers to:
- Group related data together
- Build scalable applications
- Represent complex data structures easily
Common Uses of Objects
Objects are widely used in JavaScript for:
- Storing user data
- Managing products in e-commerce applications
- Handling API responses
- Structuring application data
Example:
let product = {
name: "Laptop",
price: 50000,
inStock: true
};
CRUD Operations in Objects
CRUD stands for:
- Create
- Read
- Update
- Delete
These are the basic operations we perform on object data.
Step-by-Step Example
1. Create an Object
let user = {
name: "Rahul",
age: 25
};
2. Read Data
console.log(user.name);
console.log(user.age);
screenshot of the program:
3. Update Data
user.name="Maddy"
user.age = 23;
screenshot of the program:
4. Add New Property
user.city = "Chennai";
user.branch="ECE"
screenshot of the program:
5. Delete Property
delete user.branch;




Top comments (0)