LESSON 22

Object Properties

Learning objective: Read, add, and update object properties.

Understand

Object properties can be accessed and changed.

Read properties with dot notation (user.name) or bracket notation (user['name']). You can add new properties, update existing ones, and loop over them. Bracket notation is handy when the key is in a variable.

Analogy: Accessing a property is like opening one drawer in a labelled cabinet.

See It in Action

Updating and adding:

const user = { name: "Sam" };
user.age = 21;        // add
user.name = "Samuel"; // update
How it works: Assigning to a new key adds a property; assigning to an existing key updates it.

Try It Yourself

  1. Read a property with dot notation.
  2. Add a new property.
  3. Update an existing property.

Quick Quiz

When is bracket notation especially useful?

Challenge

Take an object and add one property while updating another.

Success condition: Your object reflects both the added and updated properties.