JS Built-ins
← Date87 / 120
DatesetMonthbeginner

setMonth() β€” returns a timestamp

πŸ“– Usage Example
const d = new Date(2024, 0, 15)
d.setMonth(5)
d.getMonth()  // β†’ 5 (June)

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

Date.prototype.setMonth()

setMonth() returns the new timestamp as a number.

Challenge: Verify that typeof d.setMonth(5) returns 'number'.

πŸ’‘ Hints (1)
  • β€’ All setter methods return the new timestamp in ms