JavaScript version
daysInMonth.js
// `month` is zero-based index
const daysInMonth = (month, year) => new Date(year, month, 0).getDate();
TypeScript version
daysInMonth.ts
const daysInMonth = (month: number, year: number): number => new Date(year, month, 0).getDate();