I followed the instructions in this question.
Here's my code:
edate = new Date()
edate.setYear(edate.getFullYear() + 1);
month = edate.getMonth();
console.log(month);
console.log(month.length);
This returns:
3
undefined
I followed the instructions in this question.
Here's my code:
edate = new Date()
edate.setYear(edate.getFullYear() + 1);
month = edate.getMonth();
console.log(month);
console.log(month.length);
This returns:
3
undefined
In the code you listed from the other question, the value stored in month was converted to a String. This can be done like this (concatenation with empty String causes toString() conversion):
month = '' + edate.getMonth();
A Number value does not have a length property, but a String does. This is what the original code was utilizing.
A more clear approach (as mentioned) would be to utilize the String constructor that accepts a Number as input and converts it to a String, like so:
month = String(edate.getMonth());
Or, you could call toString() directly on you the value that is returned from getMonth(), like so:
month = edate.getMonth().toString();