자바스크립트에서의 객체
const(let) 객체명 = {
속성 : 값,
속성 : 값,
}
=============================코드=============================
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<script type="text/javascript">
const product = {
name : "Galaxy S24",
type : "핸드폰",
company : "삼성"
}
// 해당 객체의 속성을 화면에 출력하는 방법 - 첫번째 방법
document.write(`제품 이름 >>> ${product['name']} <br/>`);
document.write(`제품 타입 >>> ${product['type']} <br/>`);
document.write(`제품 제조사 >>> ${product['company']} <br/>`);
document.write(`<hr>`);
// 해당 객체의 속성을 화면에 출력하는 방법 - 두번째 방법
document.write(`제품 이름 >>> ${product.name} <br/>`);
document.write(`제품 타입 >>> ${product.type} <br/>`);
document.write(`제품 제조사 >>> ${product.company} <br/>`);
document.write(`<hr>`);
// 해당 객체의 속성을 화면에 출력하는 방법 - 세번째 방법
for(let p in product) {
document.write(`${p}의 값 >>> ${proudct[p]} <br/>`)
}
</script>
</head>
<body>
</body>
</html>

=============================코드=============================
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<script type="text/javascript">
const person = {
name : "홍길동",
eat : function(food) {
document.write(`${this.name} 님이 ${food}을(를) 먹습니다.`);
}
}
document.write(`이 름 : ${person.name} <br/>`);
person.eat("커피");
</script>
</head>
<body>
</body>
</html>
