Javascript new Date() Example to Check Whether Given Year is Leap or Not in Browser

Hello, friend today we are going to see clearly what we are going to see in the article Javascript new Date() Example to Check Whether Given Year is Leap or Not in Browser. We hope you find this article very useful.

Javascript new Date() Example to Check Whether Given Year is Leap or Not in Browser

Javascript new Date() Example to Check Whether Given Year is Leap or Not in Browser

// program to check leap year
function checkLeapYear(year) {

    const leap = new Date(year, 1, 29).getDate() === 29;
    if (leap) {
        console.log(year + ' is a leap year');
    } else {
        console.log(year + ' is not a leap year');
    }
}

// take input
const year = prompt('Enter a year:');

checkLeapYear(year);

Read Also: Javascript Program to Display Current Date & Time in Browser

Final Words

Build a Svelte.js Video Converter Using FFMPEG Library Web App Using HTML5 CSS3 and Javascript We hope you find the article useful and will see you in the next article.

Hi, I'm Ranjith a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Deekshi. Here, I post about programming to help developers.

Share on:

Leave a Comment