LESSON 21

Objects

Learning objective: Group related data with objects.

Understand

Objects store related values as key-value pairs.

An object groups related data under named keys (properties). Unlike arrays, order does not matter — you access values by name. Objects model real things like a user or a product.

Analogy: An object is like a labelled folder: each label (key) holds a piece of information.

See It in Action

Creating an object:

const user = {
  name: "Sam",
  age: 20
};
console.log(user.name); // Sam
How it works: user holds two properties; user.name reads the value stored under the name key.

Try It Yourself

  1. Create an object describing a book.
  2. Log one of its properties.
  3. Add a third property.

Quick Quiz

How do objects store data?

Challenge

Model a product as an object with at least three properties.

Success condition: Your object holds named properties you can read.