Skip to content
Related Articles
Open in App
Not now

Related Articles

JavaScript program to check if a given year is leap year

Improve Article
Save Article
  • Difficulty Level : Medium
  • Last Updated : 12 Apr, 2019
Improve Article
Save Article

Prerequisite:Understanding basic JavaScript codes.
A year is leap year if following conditions are satisfied:

  • Year is multiple of 400.
  • Year is multiple of 4 and not multiple of 100.


  • Get the value of input field by using document.getElementById(“year”).value
  • Check the given year is leap year or not by using JavaScript expression and display its value.


<!-- HTML code to implement the given year is 
    leap year or not -->
<!DOCTYPE html>
        JavaScript to check leap year
    Input Year: <input type="text" id = "year"/>
    <input type="button" id="button" onClick="isLeapYear()"
            value="Check Leap Year">
    <p id="GFG"></p>
    <!-- JavaScript code to check given year is
        leap year or not -->
        function isLeapYear() {
            var year= document.getElementById("year").value;
                = (year % 100 === 0) ? (year % 400 === 0)
                                     : (year % 4 === 0);


  • Before input year:
  • After input leap year:
  • After input not leap year:

My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!