Skip to content

Latest commit

 

History

History
16 lines (12 loc) · 574 Bytes

detect-invalid-date-objects.md

File metadata and controls

16 lines (12 loc) · 574 Bytes

Detect Invalid Date Objects

If the JavaScript Date constructor fails to parse a date string, it will return an invalid Date object.

Even though it is invalid, it will still pass an instanceof check

let invalid = new Date("");
invalid instanceof Date // true

The isNaN function will return true for invalid dates and false for valid ones:

isNaN(invalid) // true

There is some nuance when working across frame boundaries. See this post.