Lesson 17 / 40
Object Literals & Properties
Create objects with literals, read properties with dot and bracket notation and add or delete keys.
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 notationAdding & 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"].