JS Built-ins
← Date28 / 120
DategetMonthbeginner

getMonth() β€” June is 5

πŸ“– 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()

June has index 5 in the 0-indexed month system.

Challenge: Verify that new Date(2024, 5, 15).getMonth() returns 5.

πŸ’‘ Hints (1)
  • β€’ June is the 6th calendar month, so its 0-indexed value is 5