How to get the current year in JavaScript?

To get the current year in JavaScript, do this: new Date().getFullYear().

Here's how you do it:

const year = new Date().getFullYear();

console.log(year); // 2022