JS Built-ins
← Date90 / 120
DatesetMonthintermediate

setMonth() β€” set to 11 (December)

πŸ“– 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()

Setting month to 11 gives December (the maximum valid month index).

Challenge: Verify that after setMonth(11), getMonth() returns 11.

πŸ’‘ Hints (1)
  • β€’ December = month index 11, the last valid month value