Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialSufiyaan Haroon
Full Stack JavaScript Techdegree Student 9,558 PointsWhat does it mean???
'What does this code mean:'
function getYear () {
var year = new Date().getFullYear();
return year
}
getYear()
var yearToday = getYear()
especially this line:
var year = new Date().getFullYear();
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JavaScript Basics</title>
</head>
<body>
<script src="script.js"></script>
</body>
</html>
2 Answers
Tomasz Halaczkiewicz
21,845 PointsIt means you want only a Year from the entire date. For example: today is Saturday Jul 15 2017 [Day of the week, Month, Day, Year] and when you say to a program .getFullYear() it gives you only '2017' and doesn't give you month nor day.
I hope that's clear enough, don't hesitate to ask again though.
Tomasz Halaczkiewicz
21,845 PointsThe Date object is used to work with dates and times.
Date objects are created with new Date().
The Date object is build-in to JavaScript so you can just use it. In this case you use it to get the current year, in fact you are getting full date in the moment you call it and this part ".getFullYear()" indicates you only want the year part of todays date
Sufiyaan Haroon
Full Stack JavaScript Techdegree Student 9,558 PointsCan you explain me what .getFullYear()
means, in more common words?