//Optional CHaining
const bob = {
name: 'Julia',
age: 20,
}
const anna = {
name:'Julia',
age:20,
job:{
title:'software engineer'
}
}
//Bad
//job이 있을수도 있고 없을수도 있고, 타이틀을 보여줘야한다
functioin displayJobTitle (person){
if(person.job && person.job.title) {
console.log(person.job.title);
}
}
// Good
function displayJobTitle (person){
if(person.job?.title){
console.log(person.job.title);
}
}
// optional chaining , nullish
function displayJobTitle(person){
const title = person.job?.title ?? 'No Job yet';
console.log(title);
}