nullish chaining code example
Example 1: optional chain operator
const adventurer = {
name: 'Alice',
cat: {
name: 'Dinah'
}
};
const dogName = adventurer.dog?.name;
console.log(dogName);
// expected output: undefined
Example 2: optional chaining
const array = [1,2,3,4,5];
let arrItem = array?.[4];
console.log(arrItem); /// 5