JavaScript program that displays how many days are in the month for a given month and year
Posted by SceDev
Last Updated: March 01, 2024

Write a JavaScript program that displays how many days are in the month for a given month and year.

Code:

function daysInMonth(month, year) {
    return new Date(year, month, 0).getDate();
}

const month = 3; //March
const year = 2024;
const days = daysInMonth(month, year);

console.log(`Number of days in ${month}/${year}: ${days}`);