안녕하세요 lika-7입니다
이번시간에는 Shorthand Property Names/Property Value Shorthand 패턴에 대해 정리 하겠습니다
Shorthand Property Names/Property Value Shorthand 패턴이란?
💡
객체를 생성 할 때, 객체 리터럴과 변수 이름이 객체의 속성 이름과 일치할 경우, 속성 이름을 생략 할 수 있는 패턴을 Shorthand Property Names/Property Value Shorthand 패턴 이라고 부릅니다.
예시코드
const name = "John";
const age = 30;
const person = {
name: name,
age: age
};
위 코드에서 name 변수와 age 변수를 사용해 person 객체를 생성하고 있습니다.
JavaScript에서는 변수 이름과 객체 속성 이름이 같을 때, 아래와 같이 간결하게 작성할 수 있습니다.
const name = "John";
const age = 30;
const person = {
name,
age
};