Javascript program to find leap year

Program to find if a given year is leap year or not in javascript.

Example

Input:
1888
1885

Output:
true
false

Program to find leap year in javascript.

Normal year in a calendar has 365 days with month February having 28 days, but a leap year has 366 days in which Feb has 29 days.

A leap year has following characteristics in Gregorian calendar.

  • A year that is exactly divisible by 400.
  • Or a year that is divisible by 4 but not divisible by 100.

All we have to do in this program is to check if the given year satisfies any of the above condition or not. If it does then return true else return false.

const isLeapYear = (year) => {
  //Is divisible by 400
  if(year % 400 === 0){
    return true;
  }
  
  //Is divisble by 4 and not divisible by 100
  if(year % 4 === 0 && year % 100 !== 0){
    return true;
  }
  
  return false;
}
Input:
console.log(isLeapYear(1888));
console.log(isLeapYear(2020));
console.log(isLeapYear(2019));

Output:
true
true
false