Challenge: Validate the Date

This challenge will test your skills in implementing arrow functions and "prototype.toString" in JavaScript.

Problem statement #

isValidDate function takes the parameter dateString, using it to create a Date object. Your task is to validate whether this date object is valid or not. In particular, you need to check for two cases:

  • It is a valid date object

  • Time (if passed in dateString) is valid

Return true if it is valid and false otherwise.

Input #

A string containing the date

Output #

Boolean value-true or false

Sample input #

dateString = "May 8, 2016 10:12:00"
dateString = "hello"

Sample output #

true
false

Level up your interview prep. Join Educative to access 80+ hands-on prep courses.