JS Built-ins
← Date95 / 120
DatesetDateintermediate

setDate() β€” overflow rolls to next month

πŸ“– Usage Example
const d = new Date(2024, 0, 15)
d.setDate(1)
d.getDate()  // β†’ 1

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

Date.prototype.setDate()

Passing a day value greater than the month's length causes the date to overflow into the next month.

Challenge: Verify that setting day 32 on January rolls over to February.

πŸ’‘ Hints (1)
  • β€’ January has 31 days; day 32 = day 1 of February. This overflow behaviour is by spec.