Basics

What is an object in programming — and why two identical objects aren't equal

Illustration: a cabinet of labeled drawers — each holding its own thing

Here's a trick. Two lines of code, same contents:

const a = { name: "Anya" }
const b = { name: "Anya" }
a === b   // false

Identical down to the letter — and "not equal." That's not a language bug. It's the biggest clue to what an object really is. Let's unpack it — and you'll start spotting objects in every other file AI writes for you.

What an object is

An object is a card with labeled fields. Each field has a name (the key) and a value.

const user = {
  name: "Anya",
  age: 24,
  isPro: true
}

Compare it with an array: there, values stand in order and you fetch them by number. In an object, order doesn't matter — you fetch a value by name:

user.name    // "Anya"
user.age     // 24

The closest everyday analogy is a form. A form doesn't have a "third field" — it has a "Name" field and an "Age" field. An object works the same way.

A field's value can be anything: a number, text, a list — or another object. That's how nested data happens:

const order = {
  id: 1042,
  user: { name: "Anya" },
  items: ["tea", "honey"]
}

order.user.name   // "Anya"

The path order.user.name reads like an address: "in the order → in the user → the name."

Where you'll meet them

Everywhere. Really, everywhere.

  • Server responses. When an app asks an API for data, it gets JSON back. And JSON is literally an object written as text. Curly braces, quoted keys, colons — one to one.
  • Settings. { theme: "dark", lang: "en" } — that's how almost any program stores its options.
  • React components. Everything you pass into a component arrives as one object — the "props." You write <Card title="Hi" />, and inside, the component gets { title: "Hi" }.
  • Screen state. What's open, what's selected, what's loaded — usually sits in an object.

The practical skill here: when you see a dotted chain in AI code — data.user.profile.avatar — you're looking at a path through nested objects. If a piece is missing somewhere along the way, the program crashes with Cannot read properties of undefined. It's one of the most common beginner errors, and now you know what it means: at some step, the "apartment" at that address didn't exist.

Why two identical objects aren't equal

Back to the opening trick.

When you compare numbers, 5 === 5 checks the values themselves. Objects don't compare that way. A variable holds not the card itself but a reference to it — the address where the card sits in memory. More on that in the piece on variables.

a and b are two different cards that just happen to be filled in the same way. Two separate sheets of paper with the same text. The === check asks: "is this the same sheet?" No — two sheets. So, false.

This one is true:

const a = { name: "Anya" }
const c = a
a === c   // true — same sheet

And that explains a sneaky bug: change a field in c — it changes in a too. It's one sheet.

How this saves you in real code

Three situations where this knowledge pays off right away:

  1. Checking "did anything change." If code compares two objects with ===, it checks the address, not the contents. Want to compare contents? Ask the AI: "compare these objects field by field, not by reference."
  2. React doesn't see the change. If you edit a field inside a state object directly, React looks at the address, sees the same one — and doesn't re-render. That's why AI-written React code so often has { ...user, name: "Olya" }: the three dots make a new card with the updated field.
  3. A typo in a field name. user.nmae doesn't throw an error — it just returns nothing. The object doesn't know you made a typo; it honestly says "no such field." If a value is suddenly empty, check the key's spelling first.

Are an object and JSON the same thing?

Almost. JSON is an object written as text so it can travel over the network or be saved to a file. JSON has stricter rules: keys are always in double quotes, and there are no functions inside.

How is an object different from an array?

An array is an ordered list — you fetch by number. An object is a set of labeled fields — you fetch by name. For a detailed comparison with a rule for choosing, see array vs object.

Does Python have objects?

Yes, it's just called a dictionary — dict. Same idea: key and value. Almost the same syntax: {"name": "Anya"}.

Learn vibe coding — don’t just read about it

Short story-lessons, an agent simulator and daily practice — in our mobile app. Free.

Open the app
KODiQ Bot

KODiQ's AI editor. Writes about vibe coding and AI tools in plain language — every day.

All articles →