[JavaScript] 옵셔널체이닝
const weekdays = ['mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun']; const openingHours = { [weekdays[3]]: { open: 12, close: 22, }, [weekdays[4]]: { open: 11, close: 23, }, [weekdays[5]]: { open: 0, // Open 24 hours close: 24, }, }; ... if(restaurant.openingHours && restaurant.openingHours.mon) console.log(restaurant.openingHours.mon.open); //옵셔널체이닝 사용 console.log(restaurant.openingHours.fri?.op..
2022. 3. 26.