Beehaw
  • Communities
  • Create Post
  • search
    Search
  • Login
  • Sign Up
JPDev ( JPDev@programming.dev )  to Programmer Humor@programming.dev · 3 years ago

===

programming.dev

message-square
34
link
fedilink
380

===

programming.dev

JPDev ( JPDev@programming.dev )  to Programmer Humor@programming.dev · 3 years ago
message-square
34
link
fedilink
alert-triangle
You must log in or # to comment.
  • Buttons ( Buttons@programming.dev ) 
    link
    fedilink
    English
    arrow-up
    45
    ·
    3 years ago

    https://programming.dev/post/7789832

  • Lunya \ she/it ( backhdlp@iusearchlinux.fyi ) 
    link
    fedilink
    arrow-up
    29
    ·
    edit-2
    3 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.

    • QuazarOmega ( QuazarOmega@lemy.lol ) 
      link
      fedilink
      arrow-up
      42
      ·
      3 years ago
      > 1 == 1
      true
      > 1 == '1'
      true
      > 1 === '1'
      false
      

      (from node REPL)

      Basically it’s the real equals sign perfection

    • frezik ( frezik@midwest.social ) 
      link
      fedilink
      arrow-up
      28
      ·
      3 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.

    • Mikina ( Mikina@programming.dev ) 
      link
      fedilink
      arrow-up
      12
      ·
      3 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.

      • frezik ( frezik@midwest.social ) 
        link
        fedilink
        arrow-up
        1
        ·
        3 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 ( Limitless_screaming@kbin.social ) 
      link
      fedilink
      arrow-up
      12
      ·
      3 years ago

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

    • kevincox ( kevincox@lemmy.ml ) 
      link
      fedilink
      arrow-up
      11
      ·
      3 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" 
      
    • BougieBirdie ( Bougie_Birdie@lemmy.blahaj.zone ) 
      link
      fedilink
      English
      arrow-up
      4
      ·
      3 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 ( bobbykjack@programming.dev ) 
        link
        fedilink
        arrow-up
        2
        ·
        3 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 ( clb92@feddit.dk ) 
      link
      fedilink
      English
      arrow-up
      3
      ·
      3 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

  • luciole (they/them) ( luciole@beehaw.org ) 
    link
    fedilink
    arrow-up
    12
    ·
    3 years ago

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

    • QuazarOmega ( QuazarOmega@lemy.lol ) 
      link
      fedilink
      arrow-up
      19
      ·
      3 years ago
      x 👈 5
      
      • xedrak ( xedrak@kbin.social ) 
        link
        fedilink
        arrow-up
        13
        ·
        3 years ago

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

        • OpenStars ( OpenStars@startrek.website ) 
          link
          fedilink
          English
          arrow-up
          5
          ·
          3 years ago

          You sonnofabitch I’m in!:-P

      • OpenStars ( OpenStars@startrek.website ) 
        link
        fedilink
        English
        arrow-up
        8
        ·
        3 years ago
        x 🔫 5
        

        the pew pew principle /s

        • Malgas ( Malgas@beehaw.org ) 
          link
          fedilink
          English
          arrow-up
          8
          ·
          3 years ago

          Interpreter: Wait, x is 5?

          This code: Always has been.

          • OpenStars ( OpenStars@startrek.website ) 
            link
            fedilink
            English
            arrow-up
            4
            ·
            3 years ago

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

    • cerement ( cerement@slrpnk.net ) 
      link
      fedilink
      arrow-up
      10
      ·
      3 years ago

      :=

      • MxM111 ( MxM111@kbin.social ) 
        link
        fedilink
        arrow-up
        4
        ·
        3 years ago

        That’s delayed assignment.

        • cerement ( cerement@slrpnk.net ) 
          link
          fedilink
          arrow-up
          6
          ·
          3 years ago

          procrastination assignment

    • expr ( expr@programming.dev ) 
      link
      fedilink
      arrow-up
      1
      ·
      3 years ago

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

  • cally ( callyral@pawb.social ) 
    link
    fedilink
    English
    arrow-up
    9
    ·
    3 years ago

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

    • gandalf_der_12te ( gandalf_der_12te@feddit.de ) 
      link
      fedilink
      arrow-up
      6
      ·
      3 years ago

      Basically Java in a nutshell

  • Blackmist ( Blackmist@feddit.uk ) 
    link
    fedilink
    English
    arrow-up
    8
    ·
    3 years ago

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

  • DrunkenPirate ( DrunkenPirate@feddit.de ) 
    link
    fedilink
    arrow-up
    8
    ·
    3 years ago

    ChatGpt: 1+1≈2

    • OpenStars ( OpenStars@startrek.website ) 
      link
      fedilink
      English
      arrow-up
      2
      ·
      3 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 ( Darkaga@kbin.social ) 
        link
        fedilink
        arrow-up
        2
        ·
        3 years ago

        4chan: “Gamer words”

        • OpenStars ( OpenStars@startrek.website ) 
          link
          fedilink
          English
          arrow-up
          2
          ·
          3 years ago

          No, that’s Discord 🙃

  • xedrak ( xedrak@kbin.social ) 
    link
    fedilink
    arrow-up
    5
    ·
    3 years ago

    cries in PHP

  • tiredofsametab ( tiredofsametab@kbin.social ) 
    link
    fedilink
    arrow-up
    2
    ·
    3 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)

  • I Cast Fist ( ICastFist@programming.dev ) 
    link
    fedilink
    arrow-up
    2
    ·
    3 years ago

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

  • Tyfon ( Tyfon@programming.dev ) 
    link
    fedilink
    arrow-up
    2
    ·
    3 years ago

    I’m JavaScript developer. I love coding WebApps. JS sucks💩.

  • thericcer ( thericcer@reddthat.com ) 
    link
    fedilink
    arrow-up
    1
    ·
    3 years ago

    Any Verilog devs?

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
    • If the mod doesn’t find it funny, you’re banned. Ha-ha!.. For real: do not use the community for “statements”. There are other places for such content. Keep it chill and funny.
Visibility: Public
globe

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

  • 962 users / day
  • 3.54K users / week
  • 5.04K users / month
  • 8.2K users / 6 months
  • 463 local subscribers
  • 33.8K subscribers
  • 1.61K Posts
  • 26.7K Comments
  • Modlog
  • mods:
  • Feyter ( Feyter@programming.dev ) 
  • adr1an ( anzo@programming.dev ) 
  • BurningTurtle ( BurningTurtle@programming.dev ) 
  • Pierre-Yves Lapersonne ( pylapp@programming.dev ) 
  • BE: 0.19.15
  • Modlog
  • Legal
  • Instances
  • Docs
  • Code