[TIL] Optional Chaining

Wontae·2020년 9월 20일
0
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

[MDN 참조]

React에서 map을 돌리다보면 에러가 발생하는데 이를 방지할 수 있다.

profile
안녕하세요! 프론트엔드 개발자 정원태입니다.

0개의 댓글