Date Get Full Year Method
It’s syntax be like –
let date = new Date(); let year = date.getFullYear(); // 2020
let date = new Date(0);
Now, we declare an another variable year and assign a result return from getFullYear() method on date variable.
let year = date.getFullYear();
Finally, we are checking the value of year using console log.
Any guess what should be the output above code statement ?
Now, you know the answer is 1970 but why because we haven’t provided any proper date to a date object. Let me explain
If you console the date variable you get something like.
Thu Jan 01 1970 05:30:00 GMT+0530 (India Standard Time)
At last, That’s why we get an answer “1970“.
Let me know in the comment section, what you think about it.
I hope you understand the concept and logic behind it.
But wait, i have something more for you –
- JS Quiz – string match regexp can extract a number value
- JS Quiz – what is the math random function range
And last but not the least, don’t forget to like, comment and share. It gives us a morale boost to remain to continue. Also, join our Facebook Page
If you have any questions, please feel free to ask me in the comment section and also let me know if you have any suggestions. As suggestions are always welcome.