Quantcast
Channel: User Hamfri - Stack Overflow
Viewing all articles
Browse latest Browse all 42

Answer by Hamfri for How to determine whether a year is a leap year in JavaScript

$
0
0

The following code block will work well on Javascript and also on Typescript if you remove the function keyword. To understand the logic behind this implementation have a look at this link How to determine whether a year is a leap year.

 function isLeapYear(year) {    let isLeapObj = {};    if ((year % 4 === 0 && year % 100 != 0) || year % 400 === 0) {      isLeapObj['isLeap'] = true;      isLeapObj['days'] = 366;    } else {      isLeapObj['isLeap'] = false;      isLeapObj['days'] = 365;    }    return isLeapObj;  }x = isLeapYear(2020);console.log(x);

For Javscript use the following code


Viewing all articles
Browse latest Browse all 42

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>