Objects in JavaScript
In JavaScript, objects are used to store collections of related data and functionality. While arrays store multiple values in a list, objects store data in the form of key-value pairs.
Objects are very important in JavaScript because they help represent real-world entities such as users, products, or students. For example, a student object can store information like name, age, and course in a single structure.
What is an Object?
An object is a data structure that stores information in the form of properties. Each property consists of a key and a value.
Example:
In this example:
- name, age, and course are keys
- "Rahul", 20, and "Computer Science" are values
Accessing Object Properties
Object properties can be accessed in two ways:
1. Dot Notation
Output:
2. Bracket Notation
Output:
Adding New Properties
You can add new properties to an object after it has been created.
Updating Object Properties
Existing properties can also be modified.
Deleting Object Properties
JavaScript provides the delete keyword to remove a property from an object.
Objects with Methods
Objects can also contain functions. When a function is stored inside an object, it is called a method.
Looping Through Object Properties
You can use the for...in loop to iterate through object properties.
Why Objects are Important
Objects are widely used in JavaScript because they allow developers to organize complex data in a structured way. Most modern JavaScript frameworks such as React, Angular, and Node.js rely heavily on objects.
Objects make it easier to represent real-world entities and manage related data within a single structure.
Conclusion
Objects are one of the most powerful features of JavaScript. They allow developers to store data as key-value pairs and build structured, organized programs.
By learning how to create, access, update, and loop through objects, developers can manage complex data more effectively in JavaScript applications.
In the next tutorial, you will learn about Functions in JavaScript, which allow developers to create reusable blocks of code.

