Skip to content

isLeapYear

The isLeapYear function checks if a year or a date is a leap year.

Syntax

typescript
isLeapYear(yearOrDate: number | Date): boolean;

Parameters

NameTypeDescription
yearOrDatenumber | DateThe year (e.g., 2024) or a Date instance

Returns

TypeDescription
booleanTrue if it is a leap year

Examples

typescript
isLeapYear(2024);
// => true

isLeapYear(new Date("2020-01-01"));
// => true

isLeapYear(2023);
// => false

Notes

  • Throws an error if the parameter is not a number or a valid date.
  • Useful for date calculations and leap year validation.

References

Released under the MIT License.