News for hackers. Stuff that matters.
Re:Date is out, Temporal is in by publicdebates on Monday January 12, 2026 @02:02PM (#46592723)
Guessed 2 of the first 3 questions.

Got to question 4 and gave up:

    new Date("not a date")
    1) Invalid Date
    2) undefined
    3) Throws an error
    4) null
There's literally no way of guessing this crap. It's all random.
Re:Date is out, Temporal is in by dvt on Monday January 12, 2026 @04:17PM (#46594439)
I had no idea we even had an `Invalid Date` object, that's legitimately insane. Some other fun ones:

    new Date(Math.E)
    new Date(-1)
are both valid dates lol.
Re:Date is out, Temporal is in by marcosdumay on Monday January 12, 2026 @02:30PM (#46593045)
The choice here is really surprising. I was half-expecting NaN, that you omitted.

Is there any other instance of the standard JS library returning an error object instead of throwing one? I can't think of any.

Re:Date is out, Temporal is in by jazzyjackson on Monday January 12, 2026 @04:56PM (#46594846)
I think NaN itself is a bit of an error object, especially in how it's passed through subsequent math functions, which is a different choice than throwing up.

But besides that I think you're right, Invalid Date is pretty weird and I somehow never ran into it.

One consequence is you can still call Date methods on the invalid date object and then you get NaN from the numeric results.

Re:Date is out, Temporal is in by WorldMaker on Monday January 12, 2026 @08:58PM (#46596560)
The fun trick is that Invalid Date is still a Date:

    > let invalid = new Date('not a date')
    > invalid
    Invalid Date
    > invalid instanceof Date
    true
You were half-correct on expecting NaN, it's the low level storage of Invalid Date:

    > invalid.getTime()
    NaN
Invalid Date is just a Date with the "Unix epoch timestamp" of NaN. It also follows NaN comparison logic:

    > invalid === new Date(NaN)
    false
It's an interesting curio directly related to NaN.
Re:Date is out, Temporal is in by tyilo on Tuesday January 13, 2026 @03:30AM (#46598537)
> Invalid Date is just a Date with the "Unix epoch timestamp" of NaN. It also follows NaN comparison logic: > > > invalid === new Date(NaN) > false

This is just because a JS Date is an object and have nothing to do with the inner representation.

    > new Date(0) === new Date(0)
    false
Re:Date is out, Temporal is in by winstonp on Monday January 12, 2026 @02:15PM (#46592875)
the new Date() constructor is an amalgamation of like 5 different specs, and unless the input matches one of them, which one kicks in is up to the implementer's choice
Re:Date is out, Temporal is in by just6979 on Thursday January 15, 2026 @12:51PM (#46636391)
I think you got it backwards. The only way is guessing, it's all random.

It's the internal inconsistencies that get me. Like, OK, I understand that there might be some quirks, maybe due to some weird backwards compatibility or technical limitation, but there are multiple incompatible quirks _inside_ this single interface! It's terrible, and things like this are a huge part of the reason JS was long considered (and sometimes still is) a Not So Good language.