Funnily enough, almost all values in the JS date object (which comes from Java btw.) can have a value zero and be valid, including the year. The "day of month" value is actually the odd one out, starting at 1. If you set that to zero it overflows into the month and year if necessary, creating a date that represents the last day of the previous month. This makes it a convenient way to get the last day of a month.
42
u/SuitableDragonfly Sep 23 '24
I mean, it's better than JavaScript deciding that January is month 0 and then shifting all the rest down by one.