// Set Xmas' month and day properties to Christmas // Note: Subtract one from month (0 = Jan, 1 = Feb, etc.) Xmas.setMonth(11); Xmas.setDate(25);
This section of code uses the setMonth() and setDate() methods of the date object to change the date held inside of Xmas to December 25th. To change the day property of a date object, JavaScript supplies the setDate() method, and not a setDay() method as you might expect. Likewise, the setDate() method only changes the day, and not the entire date, so it requires only one parameter. The object was created with the current year, so it is unnecessary to change the year.
The syntax for the setMonth() method is:
Date.setMonth(theMonth)
where theMonth is an integer between 0 and 11. Because Xmas is a date object, and we want to change the value of the date inside Xmas, we call the setMonth() method on Xmas (Xmas.setMonth()). Likewise, since today is a date object, we could call the setMonth() method on today (today.setMonth()).