JS Built-ins
← Date91 / 120
DatesetDatebeginner

setDate() β€” set to day 1

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

Sets the day-of-month and returns the new timestamp.

Challenge: Verify that after setDate(1), getDate() returns 1.

πŸ’‘ Hints (1)
  • β€’ setDate() sets the day-of-month (1-indexed); month and year are unchanged