How getFullYear() function works in JavaScript

The getFullYear() function is a native JavaScript function that returns the year represented by the specified date object. This function was released in 2002 and was initially used in Internet Explorer 5.

The date object can be either a Date object or a String object that represents a date.

If you specify a Date object, the function will return the year represented by the date's year property.

If you specify a String object, the function will return the year represented by the first four characters of the String object's date property.

Here's an example of how to use the getFullYear() function:

var today = new Date();
var year = today.getFullYear();
console.log(year);

The code above will log the current year to the console.

Here's an example of how to use the getFullYear() function with a String object:

var date = "1/1/2018";
var year = date.getFullYear();
console.log(year);

The code above will log the current year to the console.

💡
Need a writer? Want to work with me? I have a subscription copywriting service available at Zipply.io. Subscribe to a set number of words and split it into as many copy assets as you need. Scale your startup, small business, or MVP. Upgrade, downgrade and pause at any time. Start your subscription here.