Object Basics
👨💼 We need to store related pieces of information together. Objects let us
group data with meaningful property names.
Creating an object:
const person = {
name: 'Alice',
age: 30,
city: 'New York',
}
Accessing properties:
console.log(person.name) // "Alice" (dot notation)
console.log(person['age']) // 30 (bracket notation)
- Create an object
bookwith properties:title,author,year, andisRead(boolean) - Log the title using dot notation
- Log the author using bracket notation
- Change
isReadtotrue - Add a new property
ratingwith a number value - Log the entire object
💰 You can add properties to existing objects:
person.country = 'USA'