leap year formula js code example

Example 1: find leap year javascript

function isLeap(year) {
   if (year % 4 === 0) {
      if (year % 100 === 0){
         if (year % 400 == 0){
            return ("Leap year.");
         } else {
            return ("Not leap year.");
         }
      } else {
         return ("Leap year.");
      }
   } else{
      return ("Not leap year.");
   }
}

Example 2: js leap year calculator

// https://www.mathsisfun.com/leap-years.html 
function isLeapYear(year) { 

    if(year % 400 === 0){
        return (year + " is a leap year.");
    } if(year % 100 === 0){
        if(year % 400 === 0){
            return (year + " is a leap year.");
        } else {
          return (year + " is not a leap year.");
        }
    } if (year % 4 === 0){
        if(year % 100 === 0){
           return (year + " is not a leap year.");
        } else {
        return (year + " is a leap year.");
        }
    } else {
        return (year + " is not a leap year.");
    }

}

// leap year
// isLeap(2024);

// not leap year 
// isLeap(1930);