새소식

프론트엔드/javascript

Shorthand Property Names/Property Value Shorthand 패턴

  • -

안녕하세요 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
};

'프론트엔드 > javascript' 카테고리의 다른 글

history 객체  (0) 2023.10.05
optional chaining  (0) 2023.10.04
Document 객체  (1) 2023.10.04
String.prototype.trim()  (0) 2023.10.03
프로퍼티 정의 object.defineProperty  (0) 2023.10.03
Contents

포스팅 주소를 복사했습니다

이 글이 도움이 되었다면 공감 부탁드립니다.