I've been working with dates in node for a while now. I had an issue where the date was giving the wrong date after adding months. I ran some tests.
const d = new Date('2021-05-01');
console.log(d); // 2021-05-01T00:00:00.000Z
d.setMonth(d.getMonth() + 1);
console.log(d); // 2021-05-31T00:00:00.000Z
I was confused why this wasn't just giving me 2021-06-01 after running
console.log(d.getMonth())
I realized it was returning 3 which is not May
Then I ran
console.log(d.toDateString())
Which gave me Fri Apr 30 2021
So my question is why does it make new Date('2021-05-01') actually April 30th?