Test whether a year is a leap year under the Gregorian calendar—the rule used by most civil calendars today.
Rule
A year is a leap year when it is divisible by 4, except years divisible by 100 are common years unless they are also divisible by 400. Equivalently: leap when (year % 4 === 0 && year % 100 !== 0) || (year % 400 === 0).
Examples
| Year | Leap? | Reason |
|---|---|---|
| 2024 | Yes | Divisible by 4, not a century exception |
| 1900 | No | Divisible by 100 but not by 400 |
| 2000 | Yes | Divisible by 400 |
Limitations
Only accepts integer years from 1 through 9999. Does not cover Julian calendar reforms, lunar calendars, or locale-specific holiday tables.
When to use it
Verify calendar rules in homework, sanity-check date libraries, or explain why century years like 1900 are not leap years while 2000 is.