From MDN:
Date objects are based on a time value that is the number of milliseconds since 1 January 1970 UTC.
This means that when you're creating a new Date object, it will give you 1970 + the amount of milliseconds you pass in. By subtracting 1970 from the date's year, you get the time difference in years.