Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,911 questions

51,843 answers

573 users

How to check if year is leap year in Node.js

3 Answers

0 votes
function isLeapYear(year) {
    return (year % 4 === 0 && year % 100 !==0 || year % 400 === 0);
}
 
console.log(isLeapYear(2020)); 
 
console.log(isLeapYear(2023)); 
 
 
     
     
/*
run:
     
true
false
     
*/

 



answered Mar 7, 2022 by avibootz
0 votes
function printLeapYear(year) {
     if (year % 4 == 0) {
        if (year % 100 == 0) {
            if (year % 400 == 0)
                console.log("Leap year");
            else
                console.log("Not a leap year");
        }
        else
            console.log("Leap year");
    }
    else
        console.log("Not a leap year");
}
 
printLeapYear(2020);
 
printLeapYear(2023); 
 
 
 
     
     
/*
run:
     
Leap year
Not a leap year

*/

 



answered Mar 7, 2022 by avibootz
0 votes
function isLeapYear(year) {
    return new Date(year, 1, 29).getDate() === 29;
}
 
console.log(isLeapYear(2020)); 
 
console.log(isLeapYear(2023)); 
 
 
     
     
/*
run:
     
true
false
     
*/

 



answered Mar 7, 2022 by avibootz

Related questions

1 answer 83 views
83 views asked Dec 12, 2024 by avibootz
1 answer 133 views
133 views asked Dec 12, 2021 by avibootz
2 answers 132 views
132 views asked Oct 16, 2022 by avibootz
3 answers 159 views
159 views asked Oct 16, 2022 by avibootz
3 answers 235 views
1 answer 101 views
...