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 trialArthur Kakulidis
2,657 PointsWhat is a "new" operator? I also don't understand what I'm doing wrong. Please help
I don't understand the "new" operator and don't understand what I'm doing wrong in this task.
function getYear() {
var year = new Date().getFullYear();
return year;
}
getYear ()
var yearToday = "year"
<!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>
1 Answer
Erwan EL
7,669 Pointsnew Date() and getFullYear() are two native functions of javascript you can try both of them in your browser console pushing ctrl + shift + i The new create an instance of Date() you can read more here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/new
new Date();
// return
Sun Dec 10 2017 18:59:41 GMT-0500 (Amér. du Sud - Pac.)
new Date().getFullYear()
//return
2017
the getFullYear function filter the year of new Date()
Arthur Kakulidis
2,657 PointsArthur Kakulidis
2,657 PointsI also don't get where the .getFullYear come from and what it is.