Update isLeapYear.md
This commit is contained in:
@ -1,16 +1,14 @@
|
|||||||
---
|
---
|
||||||
title: isLeapYear
|
title: isLeapYear
|
||||||
tags: function,date,beginner
|
tags: date,beginner
|
||||||
---
|
---
|
||||||
|
|
||||||
Returns `true` if year is leap year.
|
Returns `true` if the given `year` is a leap year, `false` otherwise.
|
||||||
|
|
||||||
Use `new Date()`, set the date to 29st february `year`, check if the month is equal with 1 then return `true`
|
Use `new Date()`, setting the date to February 29th of the given `year` and use `Date.prototype.getMonth()` to check if the month is equal to `1`.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const isLeapYear = (year) => {
|
const isLeapYear = (year) => new Date(year, 1, 29).getMonth() === 1;
|
||||||
return new Date(year, 1, 29).getMonth() === 1
|
|
||||||
}
|
|
||||||
```
|
```
|
||||||
|
|
||||||
```js
|
```js
|
||||||
|
|||||||
Reference in New Issue
Block a user