Number of days in a month
1 // 'month' is starting from 0
2 // daysInMonth(2022, 1) -> 28
3 const daysInMonth = (year, month) => {
4 const dayInMs = 1000 * 60 * 60 * 24;
5 const nextMonthFirstDay = new Date(year, month + 1, 1);
6
7 return new Date(nextMonthFirstDay - dayInMs).getDate();
8 };