Rationale behind supporting "Invalid Date"

Andrew Paprocki andrew at ishiboo.com
Sat Feb 11 13:32:23 PST 2012


I'm wondering if someone can point me to any past rationale for the
decision to support Date objects in an "Invalid Date" state instead of
throwing an exception whenever the user attempts to form an invalid
date?

Tracking down the source of script errors is difficult if something
like "new Date(undefined)" is done, followed by a ".getTime()",
propagating a NaN down layers of abstraction. Additional strange cases
involve using NaN, Infinity, etc throughout the Date API.

I was curious if there is a good reason for this or if potentially
undefined / non-finite numbers could throw in a strict-mode setting. I
didn't notice this behavior in the spec, but all browsers appear to
follow the same convention.

-Andrew


More information about the es-discuss mailing list