How come Javascript Date accepts non-numeric character as year and returns it as 2001?
If you run the following:
new Date('aaaa-05-04');
it results in Fri May 04 2001 00:00:00 GMT+0200
. Shouldn't year aaaa
result in Invalid Date
? You get the same result by setting the year as b
, abc
or any other combination.
Also setting the month to non-numeric gives a valid date
new Date('aaaa-aa-01');
But not if day is set to 21:
new Date('aaaa-aa-21');
Bonus question:
new Date(1950, 30, 30);
results in Wed Jul 30 1952 00:00:00 GMT+0100
Shouldn't this also result in Invalid Date
? Instead it adds to the year.
I'm currently using Chrome 91.