0

I am newbie with javascript and trying to study this one and meet this problem. I must write a code which can return this year (for example 2021). I tried to write my code myself and here is my code

function getCurrentYear () {
var year = date.getFullYear();
return year
}

As you can see, I tried to define year by date.getFullYear();, then return year. But i failed.

Here is the answer

function getCurrentYear  () {
const date = new Date()
return date.getFullYear()
}

I do not understand why they define date as const ? and return like this ? Could you please give me the answer? Thank you very much for your time. Sorry for my English.

0 Answers0