JS Built-ins
← Date89 / 120
DatesetMonthbeginner

setMonth() β€” set to 0 (January)

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

Setting month to 0 gives January.

Challenge: Verify that after setMonth(0), getMonth() returns 0.

πŸ’‘ Hints (1)
  • β€’ Month 0 is January β€” you can reset to January with setMonth(0)