shorthand properties (프로퍼티 축약)

ES
비고
프로퍼티의 key와 value의 변수명이 동일할 경우 value 생략 가능
Tags
object
property
shorthand
안그래도 불편하다 생각하던 찰나에, eslint에서 걸러내길래 찾아보니 역시나 편한 방법이 있었다.
 
프로퍼티 명과 value명이 동일할 경우 생략하여 줄일 수 있다.

오브젝트 예시

notion image

함수 예시

const sum = ({arg1, arg2}) => { console.log(arg1+arg2) }; const arg1 = 1; const arg2 = 2; sum({arg1: arg1, arg2: arg2}); // 이렇게 불편하게 쓰지말고 sum({arg1, arg2}); // 이렇게 줄여서 쓰자