date of birth validation for 18 years javascript

Solutions on MaxInterview for date of birth validation for 18 years javascript by the best coders in the world

showing results for - "date of birth validation for 18 years javascript"
Charley
18 Jun 2019
1function isOver18(dateOfBirth) {
2  // find the date 18 years ago
3  const date18YrsAgo = new Date();
4  date18YrsAgo.setFullYear(date18YrsAgo.getFullYear() - 18);
5  // check if the date of birth is before that date
6  return dateOfBirth <= date18YrsAgo;
7}
8
9isOver18(new Date("1999-12-01")); // true
10isOver18(new Date("2020-03-27")); // false