JS Built-ins
← Date93 / 120
DatesetDatebeginner

setDate() β€” returns a number

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

setDate() returns the new timestamp.

Challenge: Verify that typeof d.setDate(1) returns 'number'.

πŸ’‘ Hints (1)
  • β€’ setDate() returns the new timestamp in ms, just like setFullYear() and setMonth()