monyet.cc
  • Communities
  • Create Post
  • Create Community
  • heart
    Support Lemmy
  • search
    Search
  • Login
  • Sign Up
@JPDev@programming.dev to Programmer Humor@programming.dev • 2 years ago

===

programming.dev

message-square
76
fedilink
677

===

programming.dev

@JPDev@programming.dev to Programmer Humor@programming.dev • 2 years ago
message-square
76
fedilink
alert-triangle
You must log in or register to comment.
  • @Buttons@programming.dev
    link
    fedilink
    English
    75•
    edit-2
    2 years ago

    https://programming.dev/post/7789832

    • @BaardFigur@lemmy.world
      link
      fedilink
      19•2 years ago

      deleted by creator

      • @schnurrito@discuss.tchncs.de
        link
        fedilink
        16•2 years ago

        by not ever using == and !=, but only === and !==

      • @blackn1ght@feddit.uk
        link
        fedilink
        10•2 years ago

        Because in reality you’re not doing stupid stuff like that in the image. And using Typescript definitely helps.

        However I’m always annoyed that the month parameter when constructing a date object is 0 based. So 1st of Jan is

        new Date(2024, 0, 1)
        
        • @BaardFigur@lemmy.world
          link
          fedilink
          8•
          edit-2
          2 years ago

          deleted by creator

        • @JaddedFauceet@lemmy.world
          link
          fedilink
          1•2 years ago

          Looks confusing at first, but I found it nice for accessing a month array.

          const months = ["Jan", "Feb", ...];
          
          months[0] === "Jan";
          
          const label = months[date.getMonth()];
          
      • @FooBarrington@lemmy.world
        link
        fedilink
        10•2 years ago

        Typescript :)

        • @ByteJunk@lemmy.world
          link
          fedilink
          3•2 years ago

          Yep. It’s the only reason I’m still somewhat sane.

          • @fidodo@lemmy.world
            link
            fedilink
            English
            2•2 years ago

            I got by without it for years, but not that I have it I have no idea how I did it back then.

      • @JaddedFauceet@lemmy.world
        link
        fedilink
        7•2 years ago

        By banishing the bad part of the language with linter.

        For instance, standard eslint preset has rules that enforce usage of ===, https://eslint.org/docs/latest/rules/eqeqeq

        These rules often come with project starter template

        • @fidodo@lemmy.world
          link
          fedilink
          English
          4•2 years ago

          And typescript is basically just a linter on steroids

      • darcy
        link
        fedilink
        7•2 years ago

        almost forced to for web front end. why you would use it anywhere else, however, i will never know

        • Turun
          link
          fedilink
          4•2 years ago

          The same reason people drive their car to buy groceries.

          You bought it for something where it was the only option, driving 30km to work everyday. But ever since you got it, the trip to the super market is kinda too hot in the summer and too cold in the winter and what if you spontaneously need to buy more than expected?

          People learn it for front end dev, and then they use what they know for back end too.

      • @FrostKing@lemmy.world
        link
        fedilink
        2•
        edit-2
        2 years ago

        Ikr? English is hard /s

  • Lunya \ she/it
    link
    fedilink
    47•
    edit-2
    2 years ago

    I still don’t understand the === operator

    Edit: I think a more type strict ==? Pretty sure I understand the point of typescript now.

    • @SzethFriendOfNimi@lemmy.world
      link
      fedilink
      129•
      edit-2
      2 years ago

      So in JavaScript there’s the assignment

      =
      

      and the comparator is

      ==
      

      Since there’s no types JS will do implicit conversion before comparison when using == in a case like this

      if(false == '0'){
          //this is true
      }
      

      But with === it doesn’t. It means literally compare these

      if(false === '0'){
          //this is false
      }else{
          //so this will execute instead 
      }
      

      But this, however, will

      var someState = false;
       if(someState === false){
          //this is true
      }
      
      • @runswithjedi@lemmy.world
        link
        fedilink
        72•2 years ago

        deleted by creator

        • idunnololz
          link
          fedilink
          23•2 years ago

          Np. closed as duplicate

    • QuazarOmega
      link
      fedilink
      68•2 years ago
      > 1 == 1
      true
      > 1 == '1'
      true
      > 1 === '1'
      false
      

      (from node REPL)

      Basically it’s the real equals sign perfection

    • @frezik@midwest.social
      link
      fedilink
      46•2 years ago

      The short answer is that your language needs === when it fucked up the semantics of ==, but it’s also too popular and you can’t fix it without breaking half the web.

      • @marcos@lemmy.world
        link
        fedilink
        2•2 years ago

        Or when it is something like Prolog, where equality is inherently a messy and complex concept.

    • @SmoothIsFast@lemmy.world
      link
      fedilink
      28•2 years ago

      It’s like the ==, but there’s one more =

    • @kevincox@lemmy.ml
      link
      fedilink
      21•2 years ago

      JS’s == has some gotchas and you almost never want to use it. So === is what == should have been.

      All examples are true:

      "1" == true
      [1, 2] == "1,2" 
      " " == false
      null == undefined 
      

      It isn’t that insane. But some invariants that you may expect don’t hold.

      "" == 0
      "0" == 0
      "" != "0" 
      
      • @Feathercrown@lemmy.world
        link
        fedilink
        English
        5•2 years ago

        One neat feature is you can compare to both null and undefined at the same time, without other falsey values giving false positives. Although that’s not necessary as often now that we have nullish coalescing and optional chaining.

        • @kevincox@lemmy.ml
          link
          fedilink
          2•2 years ago

          I just tested and Terser will convert v === null || v === undefined to null==v. Personally I would prefer to read the code that explicitly shows that it is checking for both and let my minifier/optimizer worry about generating compact code.

          • @SzethFriendOfNimi@lemmy.world
            link
            fedilink
            0•2 years ago

            Try changing to const === variable. That’s most likely what’s it doing to minimize the risk of accidental assignment.

            • @kevincox@lemmy.ml
              link
              fedilink
              3•2 years ago

              Wut? This is an automated optimizer. It is not worried about accidental assignment.

              • @SzethFriendOfNimi@lemmy.world
                link
                fedilink
                1•2 years ago

                I agree it shouldn’t. But I’ve seen linters that automatically change it since they seem to be forcing practical conventions sometimes.

                • @kevincox@lemmy.ml
                  link
                  fedilink
                  3•2 years ago

                  Linters and minifers are completely different tools.

    • @Mikina@programming.dev
      link
      fedilink
      18•
      edit-2
      2 years ago

      It’s also important if you’re checking hashes (at least, it was - if you’re using correct hashing algorithm that isn’t ancient, you will not have this problem).

      Because if you take for example “0e462097431906509019562988736854” (which is md5(“240610708”), but also applicable to most other hashing algorithms that hash to a hex string), if(“0e462097431906509019562988736854” == 0) is true. So any other data that hashes to any variantion of “0e[1-9]+” will pass the check, for example:

      md5("240610708") == md5("hashcatqlffzszeRcrt")

      that equals to

      "0e462097431906509019562988736854" == "0e242700999142460696437005736231"

      which thanks to scientific notation and no strict type checking can also mean

      0462097431906509019562988736854 == 0242700999142460696437005736231

      which is

      0 == 0 `

      I did use md5 as an example because the strings are pretty short, but it’s applicable to a whole lot of other hashes. And the problem is that if you use one of the strings that hash to a magic hash in a vulnerable site, it will pass the password check for any user who’s password also hashes to a magic hash. There’s not really a high chance of that happening, but there’s still a lot of hashes that do hash to it.

      • darcy
        link
        fedilink
        10•2 years ago

        that is terrifying

      • @frezik@midwest.social
        link
        fedilink
        1•2 years ago

        If you’re checking passwords, you should be using constant time string checking, anyway.

        More likely, you should let your bcrypt library do it for you.

    • Limitless_screaming
      link
      fedilink
      18•2 years ago

      == but for JavaScript. What you don’t understand is the == of JavaScript.

    • BougieBirdie
      link
      fedilink
      English
      6•2 years ago

      The other comments explains it in pretty good detail, but when I was learning my teacher explained it sort of like a mnemonic.

      1 + 1 = 2 is read “one plus one equals two”

      1 + 1 == 2 is read “one plus one is equal to two”

      1 + 1 === 2 is read “one plus one is really equal to two”

      And you hit the nail on the head, is that === is type explicit while == is implicit.

      • @bobbykjack@programming.dev
        link
        fedilink
        3•
        edit-2
        2 years ago

        I’d use something like:

        = becomes

        == equals

        === is identical to

        It’s funny how everyone thinks “equals” in this context should be “identical to” when, in normal language, it doesn’t really mean that at all!

    • clb92
      link
      fedilink
      English
      4•
      edit-2
      2 years ago

      Like == but more strict. The == operator will do type conversion, so 0 == '' will actually be true, as an example. Sometimes (honestly, most times) you may want to compare more strictly.

      See this StackOverflow answer: https://stackoverflow.com/questions/359494/which-equals-operator-vs-should-be-used-in-javascript-comparisons

    • @ShortFuse@lemmy.world
      link
      fedilink
      4•
      edit-2
      2 years ago

      You don’t need Typescript, you need an linter (eslint).

      === is your basic equality like most languages. == will implicitly cast type.

      The breakdown is here: https://262.ecma-international.org/5.1/#sec-11.9.3

      Modern JS says to never use == unless you’re comparing against null or undefined.

    • The Assman
      link
      fedilink
      1•2 years ago

      deleted by creator

  • @Blackmist@feddit.uk
    link
    fedilink
    English
    13•2 years ago

    JS devs should have a font that turns == into ≈.

  • luciole (he/him)
    link
    fedilink
    12•2 years ago

    I wish the assignment operator wasn’t the equal sign.

    • QuazarOmega
      link
      fedilink
      19•2 years ago
      x 👈 5
      
      • xedrak
        link
        fedilink
        13•2 years ago

        Ok deal, but that means we need to change the equality operator to 👉👈

        • @OpenStars@startrek.website
          link
          fedilink
          English
          5•2 years ago

          You sonnofabitch I’m in!:-P

      • @OpenStars@startrek.website
        link
        fedilink
        English
        8•2 years ago
        x 🔫 5
        

        the pew pew principle /s

        • Malgas
          link
          fedilink
          English
          8•2 years ago

          Interpreter: Wait, x is 5?

          This code: Always has been.

          • @OpenStars@startrek.website
            link
            fedilink
            English
            4•2 years ago

            It is now, if you know what’s good for you.

    • @cerement@slrpnk.net
      link
      fedilink
      10•2 years ago

      :=

      • MxM111
        link
        fedilink
        3•2 years ago

        That’s delayed assignment.

        • @cerement@slrpnk.net
          link
          fedilink
          6•2 years ago

          procrastination assignment

    • @expr@programming.dev
      link
      fedilink
      1•2 years ago

      In Haskell, it’s the same as the mathematical = symbol.

  • @DrunkenPirate@feddit.de
    link
    fedilink
    12•
    edit-2
    2 years ago

    ChatGpt: 1+1≈2

    • @OpenStars@startrek.website
      link
      fedilink
      English
      2•2 years ago

      Reddit: 1+1=your muther (sic, x2)

      X: 1+1≈we should violently overthrow the government

      4chan: nvm, I don’t want to get banned for saying this one

      • Darkaga
        link
        fedilink
        2•2 years ago

        4chan: “Gamer words”

        • @OpenStars@startrek.website
          link
          fedilink
          English
          3•2 years ago

          No, that’s Discord 🙃

  • xedrak
    link
    fedilink
    11•2 years ago

    cries in PHP

    • @xmunk@sh.itjust.works
      link
      fedilink
      3•2 years ago

      I also came to represent my php breathren.

  • cally [he/they]
    link
    fedilink
    English
    10•
    edit-2
    2 years ago

    1+1====2! ← dreamberd developer

    • @gandalf_der_12te@feddit.de
      link
      fedilink
      9•2 years ago

      Basically Java in a nutshell

  • sooper_dooper_roofer [none/use name]
    link
    fedilink
    English
    7•2 years ago

    eight equals equals equals equals equals equals equals equals equals capital d tilde tilde

  • @jenny_ball@lemmy.world
    link
    fedilink
    7•2 years ago

    it depends on what your definition of is is

    • @gandalf_der_12te@feddit.de
      link
      fedilink
      1•2 years ago

      it depends on what your definition of is is

  • @GiM@lemmy.world
    link
    fedilink
    5•2 years ago

    parseInt(0.00000000005)

    5

    • @pftbest@sh.itjust.works
      link
      fedilink
      1•2 years ago

      classic

  • @mumblerfish@lemmy.world
    link
    fedilink
    4•2 years ago

    Mathematica also has an === operator. And :=.

    • lurch (he/him)
      link
      fedilink
      8•2 years ago

      It’s also very language specific, like Pascal/Delphi also have “:=” for assignments and “=” for comparison, etc

      • @zarkanian@sh.itjust.works
        link
        fedilink
        3•2 years ago

        That makes much more sense than the other way.

    • @Agent641@lemmy.world
      link
      fedilink
      1•2 years ago

      What does the walrus operator do?

      • @mumblerfish@lemmy.world
        link
        fedilink
        1•2 years ago

        I think it’s called ‘delayed assignment’. So it is almost like =, but you can use arguments to define functions, f[a_]:=a+2.

  • Lucien [hy/hym, comrade/them]
    link
    fedilink
    4•2 years ago

    ==== when

    • @_edge@discuss.tchncs.de
      link
      fedilink
      8•
      edit-2
      2 years ago
      ==    same (after magic)
      ===   same and same type (in Javascript)
      ====  same and same type and same actual type (in the backend before conversion to JSON)
      ===== same and same type and same actual type and same desired type (what the customer wanted)
      
    • @pocketman_stuck@lemmy.eco.br
      link
      fedilink
      2•2 years ago

      Lol

    • @pocketman_stuck@lemmy.eco.br
      link
      fedilink
      1•2 years ago

      Lolololol

  • @majestic@sh.itjust.works
    link
    fedilink
    4•2 years ago

    As a backend developer i still dont know a shit what that means

    • @UndercoverUlrikHD@programming.dev
      link
      fedilink
      9•2 years ago

      In javascript, === does not perform type coercion when checking for equality

    • @blackn1ght@feddit.uk
      link
      fedilink
      5•2 years ago

      Because in JS:

      1 == "1" // true
      1 === "1" // false
      
  • I Cast Fist
    link
    fedilink
    2•2 years ago

    Don’t forget that _.isFinite('1') returns true ;)

  • tiredofsametab
    link
    fedilink
    2•2 years ago

    1 + false ? (I have no idea in which order JS would evaluate things as I rarely have to touch that language much anymore)

Programmer Humor@programming.dev

!programmer_humor@programming.dev

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: !programmer_humor@programming.dev

Welcome to Programmer Humor!

This is a place where you can post jokes, memes, humor, etc. related to programming!

For sharing awful code theres also Programming Horror.

Rules

  • Keep content in english
  • No advertisements
  • Posts must be related to programming or programmer topics
  • 1.7K users / day
  • 6K users / week
  • 9.63K users / month
  • 19.7K users / 6 months
  • 26.8K subscribers
  • 1.85K Posts
  • 70.5K Comments
  • Modlog
  • mods:
  • Feyter
  • adr1an
  • @BurningTurtle@programming.dev
  • Pierre-Yves Lapersonne
  • BE: 0.19.3
  • Modlog
  • Legal
  • Instances
  • Docs
  • Code
  • join-lemmy.org