Lesson 16 / 38

Object Literals & Properties

Creating objects and accessing their properties.

Creating objects

Properties can be read with dot notation or bracket notation.

const person = {
  name: "Ada",
  age: 36,
  isActive: true,
};
console.log(person.name);    // dot notation
console.log(person["age"]);  // bracket notation

Adding & deleting

Assign to a new key to add a property; delete removes one entirely.

person.city = "London";
delete person.isActive;
console.log(person);

Dot vs bracket

Use bracket notation when the key is dynamic or not a valid identifier: person["first-name"].