[X]

Invalid Date Is Still A Date

luljs 1996 still works

An unparseable date is not an error, it is a real Date object whose value is NaN and does not equal itself.

In 2026: An unparseable date string does not throw. It produces a real Date object whose internal time value is NaN, so it stringifies to 'Invalid Date' and coerces to NaN. Because NaN never equals NaN, the object's numeric value does not equal itself. Detect it with Number.isNaN(+d), not by comparing dates.

Where it came from: The 'Invalid Date' value in the ECMAScript Date specification (ECMA-262). Discussed in Dr. Axel Rauschmayer's date writing. MDN

<script>
var d = new Date("spaghetti");
document.write('<p><code>new Date("spaghetti")</code> prints <b>' + String(d) + '</b></p>');
document.write('<p><code>typeof</code> it is <b>' + typeof d + '</b>, <code>instanceof Date</code> is <b>' + (d instanceof Date) + '</b></p>');
document.write('<p>Its timestamp <code>+d</code> is <b>' + (+d) + '</b></p>');
document.write('<p>By value it does not even equal itself: <code>+d === +d</code> is <b>' + (+d === +d) + '</b></p>');
</script>
sandboxed demo · breaks nothing but itselfrestart

More in luljs

all 63 in luljs › · the whole library ›