Example 1 — Read the Full Year
Call getFullYear() on a fixed local date (month index is zero-based).
const moonLanding = new Date(1969, 6, 20); // Jul 20, 1969
console.log(moonLanding.getFullYear()); // 1969 How It Works
- Build a local date.
new Date(1969, 6, 20)is July 20, 1969 (month index6). - Read the year.
getFullYear()returns1969— the absolute year. - Not two digits. You get the full value, not
69. - No side effects. The
Dateis unchanged;getFullYearonly reads.

