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!
It 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();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With