How Get the Current Year in JavaScript

To get the current year, you can call the getFullYear() method will return the year of the specified Date according to local time. The value returned by is an absolute number. For the dates between 1000 and 9999 years, the getFullYear() method returns a four-digit number.

Create a new Date() object and invoke getFullYear() method to return the current date:

Javascript create new date and invoke getFullYear() method
//Date().getFullYear() let date = new Date().getFullYear(); console.log(date);
It is important to use getFullYear(), not getYear(), as it is deprecated and can return 2-digit year at times.

Also check How to Get the Current Date and Time in JavaScript

Date and Time

There is a Date built-in object to handle all the Date and time-related operations. You can use the Date object to display the current Date and time, create a calendar, build a timer, etc. The new operator is used to create a date object.