Lesson 8: Understanding Objects

Objects are one of the fundamental concepts in programming. They allow us to group related data and functions together in a meaningful way.


Think of an object as a container that holds properties (data) and methods (functions). For example, a 'Car' object might have properties like 'color', 'model', and 'year', and methods like 'start()' and 'stop()'.

🎯 Interactive Exercise: Create Your First Object

Complete the code below to create a student object with name and age properties:

// Create a student object const student = { name: "____", // Add your name here age: ____, // Add your age here grade: "A", introduce: function() { return "Hi, I'm " + this.name; } }; // Call the introduce method console.log(student.introduce());

📝 Quick Quiz

Which of the following is the correct way to access an object's property?
A. object(property)
B. object.property
C. object->property
D. object[property]

🎮 Drag & Drop Exercise

Match the object properties with their correct values:

Properties

name
age
isStudent
grades

Values

"John Doe" (string)
25 (number)
true (boolean)
[90, 85, 88] (array)