check if over 18 javascript

Solutions on MaxInterview for check if over 18 javascript by the best coders in the world

showing results for - "check if over 18 javascript"
Ilies
25 Jun 2016
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