I have this code below to return the current year (I also have it in jsFiddle). jsFiddle keeps giving me an error: "Missing '()' invokes a constructor", and I don't know what it means or how to get rid of it. The code still works, but I'd like to know what the heck is causing the error:
HTML:
jQuery:
var currentYear = (new Date).getFullYear();
$(document).ready(function() {
$("#year").text(currentYear);
});
Thanks!
I have this code below to return the current year (I also have it in jsFiddle). jsFiddle keeps giving me an error: "Missing '()' invokes a constructor", and I don't know what it means or how to get rid of it. The code still works, but I'd like to know what the heck is causing the error:
HTML:
jQuery:
var currentYear = (new Date).getFullYear();
$(document).ready(function() {
$("#year").text(currentYear);
});
Thanks!
Share Improve this question edited Jun 20, 2020 at 9:12 CommunityBot 11 silver badge asked Sep 30, 2013 at 15:07 alexwc_alexwc_ 1,6032 gold badges25 silver badges35 bronze badges 4- you have to use new Date() – Ashok Commented Sep 30, 2013 at 15:08
- Out of interest, where are you seeing that error message? In the console? And what browser are you using? (I don't see it in either Chrome or IE) – musefan Commented Sep 30, 2013 at 15:14
- (didn't see this comment here!) when you click the JSHint button at the top of the page, red dots appear beside any errors that are present. Hover over the red dot to see what the error is. It's a great tool for new folks like myself! (Chrome) – alexwc_ Commented Sep 30, 2013 at 15:28
- 1 This is a good Q&A and should not have been downvoted. – Geek Stocks Commented Dec 10, 2016 at 5:49
3 Answers
Reset to default 21It is the new Date
part that is causing the warning. This will fix it:
var currentYear = (new Date()).getFullYear();
You are missing the brackets for Date
, it should be Date()
So:
var currentYear = (new Date()).getFullYear();
Missing a parentheses
new Date()