JS Built-ins
← Date92 / 120
DatesetDatebeginner

setDate() β€” set to day 28

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

Day 28 is valid for all months.

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

πŸ’‘ Hints (1)
  • β€’ Day 28 is safe to use for any month since even February has at least 28 days