js catch invalid date code example Example: dedecting invalid date in js function isValidDate(d) { return d instanceof Date && !isNaN(d); }