Update isLeapYear.md

This commit is contained in:
Angelos Chalaris
2020-04-15 20:34:49 +03:00
committed by GitHub
parent a7642fa103
commit bb4d16f8b3

View File

@ -1,16 +1,14 @@
---
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
const isLeapYear = (year) => {
return new Date(year, 1, 29).getMonth() === 1
}
const isLeapYear = (year) => new Date(year, 1, 29).getMonth() === 1;
```
```js