21/10/13
Ternary Operator
if랑 else if 이렇게 두개의 조건으로만 이루어진경우
ex) score > 5 ? 'good' : 'no';
Nullish coalescing operator
Bad Code
function printMessage(text) {
let message = text;
if ( text == null || text == undefined) {
message = 'Nothing to display';
}
console.log(message);
}
Good Code
function printMessage(text) {
const message = text ?? 'Nothing to display';
console.log(message);
leftExpr ?? rightExpr
왼쪽이 null, undefined이여야만 오른쪽 코드 실행
leftExpr || rightExpr
왼쪽이 falsy(거짓)인경우만 오른쪽 코드 실행
flasy = false, undefined, null, 0 , -0, Nan , "", '' ,``
함수로도 가능
Object Destructuring
Spread Syntax - Object
optional-chaining
template-literals
loops