// Function to check if a year is a leap year
function isLeapYear(year) {
return (year % 4 === 0 && year % 100 !== 0) || (year % 400 === 0);
}
// Example: Check if the year 2024 is a leap year
const year = 2024;
console.log('Is Leap Year:', isLeapYear(year));
code
Leap Year Checker
This JavaScript code defines a function isLeapYear that checks whether a given year is a leap year based on the leap year rules. The example checks if the year 2024 is a leap year, and the result is logged to the console. The comments provide explanations for each part of the code.
Leap Year
Conditional Statements