JavaScript

May 31, 2023

Leap Year In JavaScript

Leap Year


let year = 2100;
// Define variable year and initialize value
{
  if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) {
    // three conditions to find leap year
    // The number which is divided by 4 or 400 is a leap year.
    // The number that divided by 100 is not zero is leap year

    console.log(year + " is leap year");
  } else {
    console.log(year + " is not leap year");
  }
}

Output


2100 is not leap year

Tags:

by : Nehal Akhtar

Quick Summary:

Leap Year