es20212 211206 Javascript if 의 대체코드 작성방법 Javascript if 의 대체코드 작성방법 if 조건 // 나쁜 예 const welcomeMessage = ({ admin }) => { let message if (admin) message = 'Welcome, administrator!' return message } 간단한 if 조건은 아래와 같이 삼항 연산자로 대체할 수 있습니다. boolean ? valueForTrue : valueForFalse // 좋은 예 const welcomeMessage = ({ admin }) => admin ? 'Welcome, administrator!' : 'Welcome, user' const welcomeMessage = ({ admin }) => `Welc.. 2021. 12. 6. ES2021 새로운 문법 ES2021 Features ES2021 Features 논리 할당 연산자 - Logical Assignment Operators 숫자 분리 - Numeric Seperators Promise.any 와 AggregateError String.prototype.replaceAll WeakRefs 와 FinializationRegistry Objects 논리 할당 연산자 - Logical Assignment Operators // Or Or Equal x ||= y x || (x = y) // And And Equals x &&= y x && (x = y) // QQ Eqauls x ??= y x ?? (x = y) // 사용 예제 - 모두 동일한 구문입니다 if (!user.id) user.id = 1 .. 2021. 6. 28. 이전 1 다음