Lesson · JavaScript Basics

Objects and properties

An object represents one thing whose properties have descriptive names.

What you will learn

  • Create an object literal
  • Read dot and bracket properties
  • Update an object's data

Name related facts

An object literal groups properties inside braces. A property name acts as a label for its value, which is clearer than remembering a list position. Objects are common for records such as a course, book, or learner profile.

Read properties

Dot notation is concise when the property name is a valid identifier. Bracket notation accepts a string or an expression, which is useful when the property name is stored in a variable or contains characters that cannot be written after a dot.

Update with care

Assigning a new value to an existing property changes the object. Add a property only when it belongs to the data model, and avoid using one field for unrelated meanings. const can keep the object binding stable while its properties remain mutable.

Use a consistent shape

When a collection stores many similar records, keep their property names and value types consistent. This makes loops, rendering, and validation more predictable. If a property can be missing, decide how the rest of the program should handle that case.

Destructure only when it improves clarity

Destructuring can copy named property values into local names, which is convenient when a function uses several fields. It does not create a live link to those properties for primitive values. When a property may be absent, define a sensible default or handle the missing case rather than letting undefined travel unnoticed.

Javascript example
const course = { name: 'Python', lessons: 12 };
course.lessons += 1;
console.log(`${course.name}: ${course.lessons}`);
Expected output
Python: 13

Practice exercise

Create a book object with a title and page count, then log a sentence using both fields.

Show a hint

Use dot notation for these fixed property names.

Show one possible solution

const book = { title: 'Small Steps', pages: 120 }; console.log(`${book.title} has ${book.pages} pages.`);

Quick check

When is bracket notation useful?

Frequently asked questions

Are JavaScript objects the same as JSON?
<p>No. JSON is a text format with stricter rules. JavaScript objects are runtime values and can include features that JSON cannot represent, such as functions.</p>