You are viewing a free preview of this lesson.
Subscribe to unlock all 10 lessons in this course and every other course on LearningBro.
Objects are the most important data structure in JavaScript. They store collections of key-value pairs and are the foundation of almost everything in the language — from simple data containers to complex class instances.
The most common way to create an object:
const person = {
firstName: "Alice",
lastName: "Smith",
age: 30,
isStudent: false,
};
const obj = {
"full name": "Alice Smith",
"data-id": 42,
};
console.log(person.firstName); // "Alice"
console.log(person.age); // 30
console.log(person["lastName"]); // "Smith"
const key = "age";
console.log(person[key]); // 30
console.log(obj["full name"]); // "Alice Smith"
const car = { make: "Toyota" };
// Add a property
car.model = "Camry";
car.year = 2024;
// Modify a property
car.year = 2025;
Subscribe to continue reading
Get full access to this lesson and all 10 lessons in this course.