Which month is new Date(2026, 10, 17)? In which zone is a date text read? What do 31 January + a month, or a city-style date, become? Tried in your own time…
Why it matters
Dates are in every app: deadlines, schedules, timestamps. Date bugs are subtle (a month off by one, a day shifted by the zone, 31 January + a month becoming March) and rarely caught before production. Know the traps and your dates come out right.
The key idea
Months from 0, a date-only text read as UTC, months that overflow
Common mistakes
Thinking months count from 1new Date(2026, 0, 1) is 1 January. Months 0 to 11; to show one as a number, add 1: getMonth() + 1.
Parsing 'YYYY-MM-DD' and expecting local time It is read as UTC, so in zones west of UTC the date slips back a day. Make it from numbers, add a time ('…T00:00'), or keep a date with no time as text.
Not checking for an Invalid Date A failed parse gives an Invalid Date (a silent NaN), not an error. Validate: !Number.isNaN(d.getTime()).
Try it in this playground
Month 9 is October Change m to 9: the calendar says October. Months count from 0.
A date-only text'2026-10-17' is read as UTC midnight: see the blue mark on the ruler.
Add a time'2026-10-17T00:00': with a time and no Z, local time.
Run past a month’s end 31 January + setMonth(+1): February has no 31st.