JS Built-ins
← Date88 / 120
DatesetMonthbeginner

setMonth() β€” mutates the date

πŸ“– Usage Example
const d = new Date(2024, 0, 15)
d.setMonth(5)
d.getMonth()  // β†’ 5 (June)

Use setMonth() to mutate the month (0-indexed) of a Date object in place and get back the updated timestamp.

Date.prototype.setMonth()

The Date object is modified in place by setMonth().

Challenge: Verify that the month changes from 0 to 5 after calling setMonth(5).

πŸ’‘ Hints (1)
  • β€’ setMonth() changes the Date object in place β€” it mutates, not creates