JS Built-ins
← Date94 / 120
DatesetDatebeginner

setDate() β€” mutates the date

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

The original Date object is changed after calling setDate().

Challenge: Verify the day changes from 15 to 20 after setDate(20).

πŸ’‘ Hints (1)
  • β€’ setDate() mutates in place β€” useful for rolling forward/back a date