JS Built-ins
← Date30 / 120
DategetMonthintermediate

getMonth() β€” 12-month cycle

πŸ“– Usage Example
const d = new Date(2024, 5, 15)  // June
d.getMonth()  // β†’ 5
// 0=Jan, 11=Dec

Use getMonth() to retrieve the zero-indexed month (0 = January through 11 = December) of a Date in local time.

Date.prototype.getMonth()

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).

πŸ’‘ Hints (1)
  • β€’ Months range from 0 (Jan) to 11 (Dec) β€” a span of 11 indices covering 12 months