Made with KolourPaint and screenshots from Kate (with the GitHub theme).

  • GreatRam@lemmy.world
    link
    fedilink
    arrow-up
    47
    arrow-down
    5
    ·
    21 hours ago

    You’re encoding more information in the typescript one. You’re saying it’s a string that will get updated.

    • masterspace@lemmy.ca
      link
      fedilink
      English
      arrow-up
      31
      arrow-down
      1
      ·
      21 hours ago

      Yeah, it’s explicitly distinct from const a: String which says it won’t change, and var a: String, which means this is legacy code that needs fixing.

        • Hotzilla@sopuli.xyz
          link
          fedilink
          arrow-up
          3
          ·
          edit-2
          15 hours ago

          True, but var and let are not same in js, so there is three.

          if(true) {

          var a = "dumdum"

          }

          console.log(a)

          Is valid and functioning javascript. With let it is not.

    • Scoopta@programming.dev
      link
      fedilink
      arrow-up
      17
      arrow-down
      2
      ·
      21 hours ago

      You aren’t though. In most languages that use the latter declaration you would prefix the declaration with final or const or the like to specify it won’t be updated.

      • calcopiritus@lemmy.world
        link
        fedilink
        arrow-up
        13
        ·
        18 hours ago

        It’s also valid rust syntax.

        But if it were rust, this meme would not make sense, since you would just type let a and type inference would do its thing. Which is much more ergonomic.

        • Victor@lemmy.world
          link
          fedilink
          arrow-up
          1
          ·
          8 hours ago

          Type inference is a pretty big thing in TypeScript as well though. In fact it’s probably the biggest thing about it, IMO.

          • calcopiritus@lemmy.world
            link
            fedilink
            arrow-up
            1
            ·
            4 hours ago

            I don’t know typescript. But if that’s the case, this meme doesn’t make much sense.

            Who writes the types of variables in a language with type inference unless forced by the compiler?

            • Victor@lemmy.world
              link
              fedilink
              arrow-up
              1
              ·
              2 hours ago

              Maybe it’s a language without type interference?

              Either way, it sometimes makes sense in TypeScript to help the type system out a little bit.

              let array: string[] = [];
              

              In this situation, the type system can’t infer that the empty array should be a string array, because there are no items to go by.

    • Hotzilla@sopuli.xyz
      link
      fedilink
      arrow-up
      2
      ·
      15 hours ago

      C# has const string a = “Hello, World”;

      var in js is legacy, and default should be let, but changing that would break everything