In the Google Apps Script Editor I have the following code
function t(){
var d = new Date;
Logger.log(d);
var y = d.getFullYear;
Logger.log(y);
if (y == 2013) {
Logger.log("yes");
} else {
Logger.log("No");
}
}
I see the following results when viewing the log.
[13-06-23 19:53:52:863 PDT] Sun Jun 23 19:53:52 GMT-07:00 2013
[13-06-23 19:53:52:864 PDT] function getFullYear() { [native code for Date.getFullYear, arity=0] }
[13-06-23 19:53:52:864 PDT] No
I thought I would see an integer or perhaps a string that is the value returned by getFullYear.
Whatever is causing this problem for me is not unique to this method.
I am sure this is pretty basic.
Thanks in advance.
This stores a reference to the getFullYear
function in y
:
var y = d.getFullYear;
This calls the getFullYear
function and stores the result of the function call in y
:
var y = d.getFullYear();
// ------------------^^
Perhaps you're confused because you can create objects with or without the parentheses (assuming you don't need to pass any arguments of course):
var d1 = new Date;
var d2 = new Date();
Both of those do the same thing but that's just a quirk/feature of the new
operator.
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