A leap year has 366 days (February has 29). In the Gregorian calendar, leap years follow the 4 / 100 / 400 rule.
Remember
year is leap ⇔
(year % 4 === 0 AND year % 100 !== 0)
OR
(year % 400 === 0)
Examples:
2024 → divisible by 4, not by 100 → leap
1900 → divisible by 100, not by 400 → not leap
2000 → divisible by 400 → leap
2023 → not divisible by 4 → not leap
Year
Why
Leap?
2024
% 4 === 0, not a century
Yes
2000
% 400 === 0
Yes
1900
century, not % 400
No
2023
not % 4
No
Approach
How to Check a Leap Year in JavaScript
Four clear steps — then write it as one expression or nested ifs.
If the year is not divisible by 4, it is not a leap year.
If it is divisible by 4 but not by 100, it is a leap year.
If it is divisible by 100, it must also be divisible by 400.
Otherwise it is not a leap year.
Method
Idea
Time
Best for
Boolean expression
One-line 4/100/400 predicate
O(1)
Interviews, short code
Nested if
Same rule, branched for reading aloud
O(1)
Explaining each condition
Pseudocode
Pseudocode
function IsLeapYear(year):
if year mod 400 == 0:
return true
if year mod 100 == 0:
return false
if year mod 4 == 0:
return true
return false
Reference
Cheat Sheet
Keep these facts handy while writing the program.
Topic
Detail
Rule
(%4 && !%100) || %400
February
29 days in a leap year
Century leap
Only if divisible by 400
Classic yes
2024, 2000
Classic no
1900, 2023
Strict equality
Prefer === / !== in JS
Try it
Live Preview
Enter any year to see each divisibility check and the final verdict.
Whole years from 1 to 9999. Tap a chip or type a year.
Result
year = 2024
2024 % 4 = 0
2024 % 100 = 24 (not a century year)
Verdict: LEAP YEAR
Code
JavaScript Programs
Start with a one-line boolean expression. Use nested ifs when you want to explain each rule out loud.
Example 1 — Boolean Expression
Encode the Gregorian rule in a single return statement.
JavaScript
function isLeapYear(year) {
return (year % 4 === 0 && year % 100 !== 0) || (year % 400 === 0);
}
const year = 2024;
if (isLeapYear(year)) {
console.log(year + " is a leap year");
} else {
console.log(year + " is not a leap year");
}