JS Built-ins
← Date83 / 120
DatesetFullYearbeginner

setFullYear() β€” date is mutated

πŸ“– Usage Example
const d = new Date(2024, 0, 15)
d.setFullYear(2030)
d.getFullYear()  // β†’ 2030

Use setFullYear() to mutate the year of a Date object in place; the month and day remain unchanged.

Date.prototype.setFullYear()

The original Date object is changed after calling setFullYear().

Challenge: Verify that the year changes from 2024 to 1990 after calling setFullYear(1990).

πŸ’‘ Hints (1)
  • β€’ setFullYear() modifies the Date in place β€” check with getFullYear() after calling it