Belgae Social
  • Communities
  • Create Post
  • Create Community
  • heart
    Support Lemmy
  • search
    Search
  • Login
  • Sign Up
tfm@europe.pub to Programmer Humor@lemmy.ml · 5 days ago

JavaScript is awesome

jsdate.wtf

external-link
message-square
23
link
fedilink
  • cross-posted to:
  • [email protected]
  • [email protected]
51
external-link

JavaScript is awesome

jsdate.wtf

tfm@europe.pub to Programmer Humor@lemmy.ml · 5 days ago
message-square
23
link
fedilink
  • cross-posted to:
  • [email protected]
  • [email protected]
new Date("wtf")
jsdate.wtf
external-link
How well do you know JavaScript's Date class?

cross-posted from: https://programming.dev/post/33754840

new Date(“wtf”)

alert-triangle
You must log in or # to comment.
  • MyNameIsRichard@lemmy.ml
    link
    fedilink
    arrow-up
    14
    ·
    4 days ago

    It is awesome, in the same way a planet killer asteroid heading straight for us is awesome!

  • AnarchistArtificer@slrpnk.net
    link
    fedilink
    English
    arrow-up
    23
    ·
    4 days ago

    This quiz was stressful. Like, there were so many times when I knew I was being cued up for a trick question, but I still fell for it.

    • tfm@europe.pubOP
      link
      fedilink
      arrow-up
      11
      ·
      4 days ago

      It’s a mess. Expectation is always wrong, basically.

  • kinttach@lemmy.zip
    link
    fedilink
    arrow-up
    9
    ·
    edit-2
    5 days ago

    In the process of being replaced.

    https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal

    JavaScript has had the Date object for handling date and time since its first days. However, the Date API is based on the poorly designed java.util.Date class from Java, which was replaced in the early 2010s; but, because of JavaScript’s goal of backward compatibility, Date sticks around in the language.

    • sp3ctr4l@lemmy.dbzer0.com
      link
      fedilink
      English
      arrow-up
      13
      ·
      4 days ago

      Damn, I thought you meant JavaScript itself was being replaced.

      • jimi_henrik@lemmy.world
        link
        fedilink
        arrow-up
        10
        ·
        4 days ago

        One can only undefined

    • Ephera@lemmy.ml
      link
      fedilink
      English
      arrow-up
      5
      ·
      4 days ago

      Hmm, I can believe that it was based on java.util.Date, but I don’t remember that being as unpredictable. I guess, a different API to begin with, would have avoided a lot of problems, though…

  • Dessalines@lemmy.ml
    link
    fedilink
    arrow-up
    8
    ·
    edit-2
    5 days ago

    You do not, under any circumstances, “gotta hand it to javascript”.

    Love this quiz btw

  • Godnroc@lemmy.world
    link
    fedilink
    English
    arrow-up
    9
    ·
    5 days ago

    Best laugh I’ve had in a while. That is some grade-A jank.

    • ozymandias117@lemmy.world
      link
      fedilink
      English
      arrow-up
      7
      ·
      5 days ago

      Have you seen https://www.destroyallsoftware.com/talks/wat

      • PeriodicallyPedantic@lemmy.ca
        link
        fedilink
        arrow-up
        1
        ·
        2 days ago

        Classic

      • Godnroc@lemmy.world
        link
        fedilink
        English
        arrow-up
        3
        ·
        3 days ago

        I have now, that’s fantastic!

  • Victor@lemmy.world
    link
    fedilink
    arrow-up
    3
    ·
    5 days ago

    Luckily the new Temporal API is shaping up.

    • Tlaloc_Temporal@lemmy.ca
      link
      fedilink
      arrow-up
      2
      ·
      4 days ago

      I quite like this one.

  • pogodem0n@lemmy.world
    link
    fedilink
    arrow-up
    2
    ·
    5 days ago

    Ah, JavaScript…

  • mogoh@lemmy.ml
    link
    fedilink
    arrow-up
    2
    ·
    5 days ago

    Ok, I get that the Date API is problematic, but I wouldn’t expect anything meaningfull from new Date("not a date").getTime() anyway. Why would you in the first place?

    • PeriodicallyPedantic@lemmy.ca
      link
      fedilink
      arrow-up
      2
      ·
      2 days ago

      Because reasonable APIs have input validation provided out of the box, so that not everybody has to reinvent the validation wheel (inevitably incorrectly).

    • Ephera@lemmy.ml
      link
      fedilink
      English
      arrow-up
      5
      ·
      4 days ago

      It’s mainly horrid, because it means you have to code extremely defensively (or I guess, use a different API).
      You can’t rely on new Date("not a date") aborting execution of your function by throwing an error. Instead, you have to know that it can produce an Invalid Date object and check for that. Otherwise a random NaN shows up during execution, which is gonna be extremely fun to try to find the source of.

      I understand that it’s implemented like that partially for historical reasons, partially because it’s often better to display “NaN” rather than nothing, but it’s still the sort of behavior that puts me in a cold sweat, because I should be memorizing all kinds of Best Practices™ before trying to code JavaScript.

    • blaue_Fledermaus@mstdn.io
      link
      fedilink
      arrow-up
      6
      ·
      5 days ago

      Parsing user input? Nonsense data coming from an API?

      • pixely@lemmy.world
        link
        fedilink
        arrow-up
        0
        ·
        edit-2
        5 days ago

        If you’re expecting shit data then you’d have unit tests for those cases so you’d know what to expect.

        • WildPalmTree@lemmy.world
          link
          fedilink
          arrow-up
          2
          ·
          4 days ago

          Maybe you don’t expect shit data; you just get it. I know, always expect it…

    • scott@lemmy.org
      link
      fedilink
      English
      arrow-up
      2
      ·
      4 days ago

      You think you’d get an error from the constructor.

  • CarrotsHaveEars@lemmy.ml
    link
    fedilink
    arrow-up
    4
    ·
    4 days ago

    Until the new Temporal API comes along, there are some libraries we can use.

    • luxon
    • dayjs
    • or compile chrono (Rust) to WebAssembly

Programmer Humor@lemmy.ml

programmerhumor@lemmy.ml

Subscribe from Remote Instance

Create a post
You are not logged in. However you can subscribe from another Fediverse account, for example Lemmy or Mastodon. To do this, paste the following into the search field of your instance: [email protected]

Post funny things about programming here! (Or just rant about your favourite programming language.)

Rules:

  • Posts must be relevant to programming, programmers, or computer science.
  • No NSFW content.
  • Jokes must be in good taste. No hate speech, bigotry, etc.
Visibility: Public
globe

This community can be federated to other instances and be posted/commented in by their users.

  • 231 users / day
  • 1.27K users / week
  • 1.28K users / month
  • 1.28K users / 6 months
  • 1 local subscriber
  • 37.2K subscribers
  • 62 Posts
  • 272 Comments
  • Modlog
  • mods:
  • cat_programmer@lemmy.ml
  • BE: 0.19.12
  • Modlog
  • Legal
  • Instances
  • Docs
  • Code
  • join-lemmy.org