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