Menu
Coddy logo textTech

Quick Review: Objects

Part of the Object Oriented Programming section of Coddy's JavaScript journey — lesson 1 of 56.

From Data Objects to Smart Objects

In Section 2 Logic and Flow, you learned how to use objects as data containers. Now, we'll transform these static data objects into dynamic, intelligent objects that can perform actions and manage their own state.

What You Already Know from Section 2:
Objects are collections of key-value pairs that let you store related data together. Think of them like containers that hold information about something.

// Object as a simple data container
const player = {
   name: "Alex",
   health: 100,
   level: 2,
   inventory: ["sword", "potion"]
};

// Accessing data
console.log(player.name);          // "Alex" 
console.log(player.health);        // 100 
console.log(player.inventory[0]);  // "sword" - access array element

// Updating data
player.health = 85;
challenge icon

Challenge

Print the player's level in the console.

Cheat sheet

Objects can store related data as key-value pairs and be accessed using dot notation:

const player = {
   name: "Alex",
   health: 100,
   level: 2,
   inventory: ["sword", "potion"]
};

// Accessing object properties
console.log(player.name);          // "Alex" 
console.log(player.health);        // 100 
console.log(player.inventory[0]);  // "sword"

// Updating object properties
player.health = 85;

Try it yourself

const player = {
   name: "Alex",
   health: 100,
   level: 2,
   inventory: ["sword", "potion"]
};

// TODO: print the player's level in the console
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Object Oriented Programming