getMonthintermediateconst d = new Date(2024, 5, 15) // June
d.getMonth() // β 5
// 0=Jan, 11=DecUse getMonth() to retrieve the zero-indexed month (0 = January through 11 = December) of a Date in local time.
There are 12 months. Adding 12 to month 0 still gives month 0 the next year.
Challenge: Verify that new Date(2024, 0, 1).getMonth() + 12 equals 12 (to show the range 0β11).