new Date("wtf")
137 points by gaffneyc
137 points by gaffneyc
This is astonishingly horrible. I love it.
That answer for “maybe 1” made me laugh out loud. Why do we do this to ourselves?
I knew it was going to try to get me with may
as a substring at some point but I still totally fell for it when it happened.
I fared much better on the first ~8 than I expected, which made me a bit more confident but also concerned since guessing Date’s behavior correctly is inconsistent with my real world experience. So past that point when I was wrong half the time it was both oddly relieving and, of course, frustrating.
See, this is why everyone is going wild over Temporal.
Okay, folks. Honest scores.
I got 12.
13 here, far better than I thought I’d score.
If anyone gets above 20, I salute you, and please take a moment to go outside once in a while.
The comedic timing in this “quiz” is fantastic.
I scored 15/28 on https://jsdate.wtf and all I got was this lousy text to share on social media.
I got 13 but almost all of them were honest guesses. I did learn to expect certain flavors of unexpected from previous answers. In reality I felt like my score was more like 6.
11, which I definitely got loosey goosey with towards the end of the quiz. I work in JS day in and day out, and I didn’t know a good chunk of these.
I scored 14/28 on https://jsdate.wtf and all I got was this lousy text to share on social media.
I got 14/28, which I guess would be considered a “passing grade”. You don’t need to know Javascript to enjoy taking this quiz, it is pure fun.
I scored 8/28 on https://jsdate.wtf and all I got was this lousy text to share on social media.
« Is that a trick?, or maybe it isn’t … oh wait… could it be that the logic isn’t followed here ? Or is it? »
So…like…why? I assume there had to be good reasons for these design decisions, right?
design decisions
I would challenge that either of those words had anything to do with what happened here.
To quote Crafting Interpreters by Robert Nystrom
Because Eich slapped JS together with roughly the same raw materials and time as an episode of MacGyver, it has some weird semantic corners where the duct tape and paper clips show through.
I suspect that
new Date("May 5")
is niceIt’s a fairly straight port from Java https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/util/Date.html#parse(java.lang.String)
Also TIL the JavaScript standard does not specify the weird Java parsing rules! It says,
The function first attempts to parse the String according to the format described in Date Time String Format (21.4.1.32), including expanded years. If the String does not conform to that format the function may fall back to any implementation-specific heuristics or implementation-specific date formats. Strings that are unrecognizable or contain out-of-bounds format element values shall cause this function to return NaN.
(the date time string format is RFC 3339, with milliseconds required, and optional 6 digit ISO 8601 extended years instead of 4 digit years.)
A lot of them seem emergent. I have no idea why you would parse a bar number as either a year or a month in 2001 though
Lots of different terrible things going together over time - I’m fairly sure at least some is still impacted by locale as well.
The most trivial and rational thing is the 0 vs “0” - consider a static language with overload:
Class Date { Date(string) { parse the string weirdly } Date(double) { time = value } }
I know the JS Date class very well, which is why I have no interest in a quiz I’ll get wrong :D
(It’s actually been a long time since I had to do anything with JS Date - literally the last time I was really doing any with it was nearly 20 years ago, making it do a better job of caching the current timezone and locale information iirc because that was showing up on page load benchmarks, and this was years before anything remotely JIT like was at all involved in JS anywhere. It may have even been before the original sunspider benchmark.)
I’m not very familiar with JavaScript. After getting the first few wrong, I thought I’d got the cut of its jib, had inferred the sort of backward reasoning it was operating under. But I kept getting them wrong. And still kept getting them wrong. My final score was 9/28, barely better than a typewriter-owning simian. I don’t understand how it can be so counter-intuitive, not just according to natural logic, but also to its own logic.
From question 12 I just picked at random. Probably a better chance that way than trying to reason about this. Correct: 8
This is why we get to call languages a monstrosity and it’s better that such things would be entirely deleted from the internet. Just delete the repositories that serve this stuff out and nip the problem in the bud.