📘 Theory

Thinking in objects: entity plus attributes

An object groups related data under one identity.

If you model a user with separate variables such as `name`, `email` and `role`, you quickly lose context. An object keeps that information connected.

That improves readability, maintenance and scalability when your application grows.

1

Entity

2

Attributes

3

Behavior

4

Advantage

Create object literals

The main syntax is simple: `{ key: value }`.

1

The most common way to create objects in JavaScript is with braces and key-value pairs separated by commas.

2

Choose semantic property names so the object is readable without extra documentation.

Read and update properties

Use dot notation for known keys and brackets for dynamic keys.

`obj.property` is direct and readable when you know the key in advance. `obj[key]` lets you access it dynamically when the key lives in a variable.

Updating or adding properties is just assignment, but it is best done intentionally so the model stays coherent.

  • Dot notation is more readable in most cases.
  • Bracket notation is necessary for dynamic keys.
  • You can create new properties at runtime.
  • Check typos carefully because a misspelled property returns `undefined`.

Object methods and `this`

A method combines behavior and data inside the same entity.

1

When you store a function inside an object, that function can use `this` to access the object's own properties.

2

This pattern is useful for building more expressive models and for avoiding repeated argument passing when the data already lives inside the object.

Safe patterns: keys, values and optional access

Inspect the structure before assuming a property exists.

`Object.keys` and `Object.values` help you inspect dynamic data. Optional chaining with `obj?.prop` avoids crashes when nested fields are missing.

These patterns are especially important when you consume external data and cannot fully control the object's shape.

  • `Object.keys(obj)` lists property names.
  • `Object.values(obj)` shows the current values.
  • `obj?.field?.subfield` gives you safer nested access.
  • `'field' in obj` checks for the existence of a key.

🧭 Key visuals

Objects in JavaScript

It supports modeling entities with semantic keys and methods.

Diagram of properties and methods inside JavaScript objects

The context of `this`

It adds visual context to the changing behavior of `this` depending on how the function is invoked.

Visual scheme of how `this` behaves in object methods and different function calls

🧪 Learn by doing

Example Guided example: a product card object Update properties and add new fields so you can see the object evolve.
Example Guided example: an object with a method Combine data and behavior with a method that produces a short summary.
Example Interactive demo: user object generator Fill out a few inputs and build an object in real time so you can visualize a JSON-like structure.
Example Interactive demo: a profile card built from an updated object Edit a person's properties and watch how a copied object feeds both the card and the code preview.

🏁 Challenges

Challenge Challenge 1: create a user profile object Declare a complete object and build a summary using dot notation.
Challenge Challenge 2: a `present` method with `this` Add a method to the object that builds a sentence from its own properties.

What is this?

I'm Cristian Eslava and I sometimes build websites so both you and I can learn and experiment. culTest

I made this in February 2026 to make learning easier for my students. The idea is to learn web development by practicing and to keep expanding the project with new topics, tests and challenges.

It draws inspiration from MDN, W3Schools, CodePen, Manz and many other web development references. I wanted to combine useful theory, runnable examples, challenges and the testing system I had already built for culTest. culTest

If you liked it, if you didn't, or if you want to get in touch, write to me at cristianeslava@gmail.com