JS Built-ins
← Date29 / 120
DategetMonthbeginner

getMonth() β€” result is an integer

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

getMonth() always returns an integer between 0 and 11.

Challenge: Verify that Number.isInteger(new Date(2024, 0, 15).getMonth()) is true.

πŸ’‘ Hints (1)
  • β€’ getMonth() always returns an integer in [0, 11]