JS Built-ins
← Date86 / 120
DatesetMonthbeginner

setMonth() β€” set to 5 (June)

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

Mutates the Date in place, setting the 0-indexed month.

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

πŸ’‘ Hints (1)
  • β€’ setMonth() uses the same 0-indexed system as the Date constructor β€” 5 = June