Menu
Coddy logo textTech

객체 빠른 복습

Coddy JavaScript 여정의 객체 지향 프로그래밍 섹션에 포함된 레슨 — 56개 중 1번째.

데이터 객체에서 스마트 객체로

섹션 2 '로직과 흐름'에서 여러분은 객체를 데이터 컨테이너로 사용하는 방법을 배웠습니다. 이제 이러한 정적인 데이터 객체를, 스스로 행동을 수행하고 자신의 상태를 관리할 수 있는 동적이고 지능적인 객체로 변환해 보겠습니다.

섹션 2에서 이미 배운 내용:
객체는 서로 관련된 데이터를 함께 저장할 수 있게 해주는 키-값 쌍의 집합입니다. 객체를 무언가에 대한 정보를 담고 있는 컨테이너라고 생각하세요.

// 단순한 데이터 컨테이너로서의 객체
const player = {
   name: "Alex",
   health: 100,
   level: 2,
   inventory: ["sword", "potion"]
};

// 데이터 접근하기
console.log(player.name);          // "Alex" 
console.log(player.health);        // 100 
console.log(player.inventory[0]);  // "sword" - 배열 요소 접근

// 데이터 업데이트하기
player.health = 85;
challenge icon

챌린지

콘솔에 플레이어의 레벨을 출력하세요.

치트 시트

객체는 관련된 데이터를 키-값 쌍으로 저장할 수 있으며, 점 표기법을 사용하여 접근할 수 있습니다:

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

// 객체 속성에 접근하기
console.log(player.name);          // "Alex" 
console.log(player.health);        // 100 
console.log(player.inventory[0]);  // "sword"

// 객체 속성 업데이트하기
player.health = 85;

직접 해보기

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

// TODO: 콘솔에 플레이어의 레벨을 출력하세요
quiz icon실력 점검

이 레슨에는 짧은 퀴즈가 포함되어 있습니다. 레슨을 시작해 문제를 풀고 진행 상황을 기록하세요.

객체 지향 프로그래밍의 모든 레슨