JavaScript Objects
Give your data structure and meaning! Learn how JavaScript objects store related information, connect properties to values, and power real-world features like student profiles and product cards.
const student = {
name: "Alex",
course: "JavaScript",
lessons: 9
};
console.log(student.name);
What Is a JavaScript Object?
Imagine you’re building a website for a school. Each student has a name, an age, a course, and an enrollment status. Those details all describe one person, so it makes sense to keep them together.
A JavaScript object stores related information as key-value pairs, also called properties and values. Each key identifies a piece of information, while its value holds the actual data.
const student = {
name: "Alex",
age: 22,
course: "JavaScript",
enrolled: true
};
console.log(student.name);
Objects use curly braces {}. Inside, each property has a key followed by a colon and a value. Commas separate the properties.
Read Information With Dot & Bracket Notation
Once an object contains information, you’ll need a way to retrieve it. JavaScript provides two common approaches: dot notation and bracket notation.
const student = {
name: "Alex",
course: "JavaScript",
lessons: 17
};
console.log(student.name);
console.log(student["course"]);
// Use a variable to select a property
const property = "lessons";
console.log(student[property]);
Dot notation is convenient when you know the property name. Bracket notation is useful when the property name comes from a variable or contains spaces or special characters.
For example, student[property] looks up the property whose name is stored in the property variable.
student.property looks for a key literally named property. It does not substitute the variable’s value.Change Object Information
Objects can be updated as information changes. You can modify an existing property or add a completely new one using assignment.
const student = {
name: "Alex",
course: "HTML"
};
student.course = "JavaScript";
student.level = "Beginner";
console.log(student);
We changed the course property and added a new level property. This makes objects useful for applications where information needs to change over time.
You can also remove a property using the delete operator.
delete student.level;
console.log(student.level);
Just like arrays, objects declared with const can still have their properties updated. The variable itself cannot be reassigned to a different object.
Give Your Objects Actions
An object can store more than information. It can also contain functions that perform actions. When a function is stored as an object property, we commonly call it a method.
const student = {
name: "Alex",
course: "JavaScript",
introduce() {
return "Hi! I'm " + this.name +
" and I'm learning " + this.course + ".";
}
};
console.log(student.introduce());
The method introduce() uses this.name and this.course to access properties on the object that receives the method call.
Methods help keep related data and behavior together. For example, a shopping cart object might contain its items and a method that calculates the total price.
this, use the regular method syntax shown above. Arrow functions handle this differently.Organize More Detailed Information
Real applications often need to store more than a few simple properties. An object can contain another object, an array, or a combination of both.
const student = {
name: "Alex",
course: "JavaScript",
contact: {
city: "Irvine",
email: "alex@example.com"
},
skills: ["HTML", "CSS", "JavaScript"]
};
console.log(student.contact.city);
console.log(student.skills[0]);
The contact property contains another object, while skills contains an array. You can use dot notation to access nested properties and array indexes to access list items.
These combinations are especially useful for student records, product catalogs, user profiles, and other structured information.
Use Object.keys(), Object.values() & Object.entries()
Sometimes you don’t know every property name in advance. JavaScript provides methods that help you inspect and loop through an object’s own enumerable properties.
const student = {
name: "Alex",
course: "JavaScript",
level: "Beginner"
};
console.log(Object.keys(student));
console.log(Object.values(student));
Object.keys() returns an array of property names. Object.values() returns an array of their values.
Another method, Object.entries(), returns pairs of keys and values that are convenient to use in a loop.
for (const [key, value] of Object.entries(student)) {
console.log(key + ": " + value);
}
The square brackets in [key, value] use destructuring to unpack each two-item entry into separate variables.
Turn Object Data Into a Student Profile
Objects are especially useful when a webpage needs to display information about a person, product, event, or account.
Instead of keeping each detail in an unrelated variable, you can store everything in one object and use it to update the page.
const student = {
name: "Alex",
course: "JavaScript",
level: "Beginner"
};
document.getElementById("studentName")
.textContent = student.name;
document.getElementById("studentCourse")
.textContent = student.course;
With matching HTML elements, JavaScript reads the object’s properties and displays them. If the object changes, you can update the webpage again to show the latest information.
Choose a property to see its value, or update the student’s course.
textContent rather than treating it as HTML. It helps prevent unexpected markup from being interpreted by the browser.Build a Student Profile Builder
Create an interactive webpage where visitors can enter their information, save it in a JavaScript object, and display a personalized student profile.
Your Mission
- Create a
studentobject containing a name, course, and skill level. - Add text inputs or dropdowns for visitors to edit those properties.
- Create an Update Profile button.
- When clicked, update the object’s properties using the form values.
- Display the updated profile on the webpage.
- Use a reusable function to render the profile.
- Test different names, courses, and skill levels.
contact object containing a city, an array of skills, and a method that introduces the student. Then add a button to display the introduction.Build Your Student Profile!
Edit the student object, customize the form, and run your code. The starter lets you update a name, course, and level. Select Load Solution to add a city, skills, and an introduction method.
What You’ve Learned
You’re Building Structured JavaScript!
You’ve learned how objects keep related information organized and make your applications easier to understand and maintain.
- Create objects using properties and values.
- Read properties with dot and bracket notation.
- Update, add, and remove properties.
- Build object methods using functions.
- Work with nested objects and arrays.
- Explore properties using
Object.keys(),Object.values(), andObject.entries(). - Create an interactive Student Profile Builder.
Next up: Strings — learn how to work with text, format messages, and transform user input!
Your Learning Journey
0 / 17 CompletedKeep going! Every completed lesson brings you closer to mastering JavaScript.
Nice Work!
You've learned how to organize related information with JavaScript objects, read and update properties, create methods, and work with nested data. You've even built your own interactive Student Profile Builder!


