API에서 유저 정보 받아와서 이름 뽑는 부분인데 콘솔에 계속 에러가 떠요. 로그인 안 된 상태에서 특히 그런 것 같아요.


const data = { status: "ok" };
console.log(data.user.name);


Uncaught TypeError: Cannot read properties of undefined (reading 'name')


data는 분명 있는데 왜 undefined라고 하는 걸까요? 서버가 user 필드를 안 줄 때가 있는 것 같긴 한데, 그럴 때마다 앱 전체가 죽어버려서 곤란하네요. 매번 if로 data.user 있는지 검사하는 것 말고 좀 깔끔하게 처리하는 방법 없을까요?