• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
JavaScriptSource

JavaScriptSource

Search 5,000+ Free JavaScript Snippets

  • Home
  • Browse Snippets
    • Addon
    • Ajax
    • Buttons
    • Cookies
    • CSS
    • Featured
    • Forms
    • Games
    • Generators
    • Image Effects
    • Math Related
    • Miscellaneous
    • Multimedia
    • Navigation
    • Page Details
    • Passwords
    • Text Effects
    • Time & Date
    • User Details
Home / Time & Date / Check if the given year is a leap year

Check if the given year is a leap year

Check if the given year is a leap year

Use new Date(), setting the date to February 29th of the given year. Use Date.prototype.getMonth() to check if the month is equal to 1.

const isLeapYear = year => new Date(year, 1, 29).getMonth() === 1;

// Examples
isLeapYear(2019); // false
isLeapYear(2020); // true

Source

https://www.30secondsofcode.org/js/s/is-leap-year

Time & Date

Related Snippets:

  • Check if a date is after another date
  • Get the date for a specific day of the week
  • Check if a date is the same as another date
  • Get a formatted list of months

Primary Sidebar

FREE UPDATES!

Get the latest updates in your inbox for FREE!

Popular Posts

Story Generator

IP Grabber – get a users IP address with JavaScript

Simple Calendar

Remove Ads

Astrological Calculator

Copyright © 2023 JavaScriptSource.com

  • About
  • Privacy Policy
  • Submit
  • FAQ
  • Jobs For Developers
  • Contact Us