nullish

    [Javascript] Nullish coalescing ("??")

    [Javascript] Nullish coalescing ("??")

    Nullish coalescing operator ?? TypeScript 3.7 부터 지원되는 논리연산자이다. 짧은 문법으로 여러 피연산자 중 그 값이 '확정되어있는' 변수를 찾을 수 있다. 왼쪽 피연산자가 null 이나 undefined 일 때, 오른쪽 피연산자를 return 한다. function printText(text) { const printText = text ?? 'noText'; console.log(printText); } printText('Hellow World'); printText(null); printText(undefined); printText(false); printText(0); 실행 결과와 같이 null과 undefiend의 경우에만 오른쪽 피연산자로 출력된다. Nu..