If you want to check if some variable contains valid date in JavaScript, this is the way that works properly in all cases:
isValidDate: function(d) {
if ( Object.prototype.toString.call(d) === "[object Date]" ) {
// it is a date, but still it could be 'Invalid date' which could make trouble
if ( isNaN( d.getTime() ) ) {
// date is not valid
return false;
} else {
// date is valid
return true;
}
} else {
// not a date
return false;
}
}