Objects in JavaScript

Javascript 9 min min read Updated: Mar 09, 2026 Beginner
Objects in JavaScript
Beginner Topic 10 of 15

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:

javascript let student = { name: "Rahul", age: 20, course: "Computer Science" };

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

javascript let student = { name: "Rahul", age: 20 }; console.log(student.name);

Output:

output Rahul

2. Bracket Notation

javascript let student = { name: "Rahul", age: 20 }; console.log(student["age"]);

Output:

output 20

Adding New Properties

You can add new properties to an object after it has been created.

javascript let student = { name: "Rahul", age: 20 }; student.city = "Delhi"; console.log(student);

Updating Object Properties

Existing properties can also be modified.

javascript let student = { name: "Rahul", age: 20 }; student.age = 21; console.log(student.age);

Deleting Object Properties

JavaScript provides the delete keyword to remove a property from an object.

javascript let student = { name: "Rahul", age: 20 }; delete student.age; console.log(student);

Objects with Methods

Objects can also contain functions. When a function is stored inside an object, it is called a method.

javascript let person = { name: "Amit", greet: function() { console.log("Hello " + this.name); } }; person.greet();

Looping Through Object Properties

You can use the for...in loop to iterate through object properties.

javascript let student = { name: "Rahul", age: 20, course: "Computer Science" }; for (let key in student) { console.log(key + ": " + student[key]); }

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.

Get Newsletter

Subscibe to our newsletter and we will notify you about the newest updates on Edugators