JS Learning

Arrays and Objects

Lesson Progress0%

Section 3 of 4

Objects Basics

Objects Basics

Topic Overview

Take your time to understand each concept. Practice with the examples below!

Objects are like digital filing cabinets where you can store related information together. Instead of numbered slots like arrays, objects use named properties (keys) to organize data.

Real-world analogy:

Think of an object like a person's ID card:

  • Name:"John Doe"
  • Age:30
  • City:"New York"
  • Job:"Teacher"

Creating objects:

const person = {
name: "Alice",
age: 25,
isStudent: true,
city: "Boston"
};

Accessing object properties:

  • Dot notation:person.name // "Alice"
  • Bracket notation:person["age"] // 25
  • Use brackets for special cases:person["first-name"]

Modifying objects:

  • Change a value:person.age = 26;
  • Add new property:person.email = "alice@email.com";
  • Remove property:delete person.isStudent;
  • Check if property exists:"name" in person // true

Why objects are powerful:

  • Group related data together logically
  • Access data by meaningful names
  • Model real-world entities
  • Perfect for complex data structures

Example - representing a product:

const product = {
name: "Laptop",
price: 999.99,
inStock: true,
colors: ["silver", "black"]
};

Ready to practice? Try the exercise below to reinforce your learning!

Try it yourself

Create a person object with name, age, and city properties. Then add a country property.

Loading...