optional chaining1 JS '.?' 연산자란? Optional chaining연산자 .?는 .(체이닝 연산자)와 유사하게 작동하지만, 참조가 nullish일 때 에러를 발생시키는 대신 undefined를 리턴한다는 차이점이 있다. 함수 호출 시 .?연산자를 사용하면 주어진 함수가 존재하지 않을 때 undefined를 리턴한다. 예시: const adventurer = { name: 'Alice', cat: { name: 'Dinah' } }; const dogName = adventurer.dog?.name; console.log(dogName); // expected output: undefined console.log(adventurer.someNonExistentMethod?.()); // expected output: undefined 참조가.. 2021. 9. 11. 이전 1 다음