JS Built-ins
← Date85 / 120
DatesetFullYearintermediate

setFullYear() β€” chaining with getFullYear()

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

After setting the year, you can immediately read it back with getFullYear().

Challenge: Verify that setting year to 2030 and reading with getFullYear() gives 2030.

πŸ’‘ Hints (1)
  • β€’ After setFullYear(), you can verify the mutation with getFullYear()