Object Property


I have a code like this:

let person = {
  name: 'Tyron',
  age: 40,
  weekendAlarm: 'No alarms needed',
  weekAlarm: 'Alarm set to 7AM'


let day = 'Tuesday';
let alarm;

if (day === 'Saturday' || day === 'Sunday' ) {
  alarm = person.weekendAlarm;
} else {
  alarm = person.weekAlarm;


When it’s run, there are three lines of result:


For the first two lines, it makes sense for me since I try to access the name and age of the object person. However, for the last line, I wonder why it show undefined because I have already defined it in the if-else statement.


That can be ignored since it is just the console telling us that console.log() has no return value.


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.