Const in JavaScript

Const in JavaScript

It's All Fucked Shirt $22.14

Homeless People Are Sexy Shirt $21.68

It's All Fucked Shirt $22.14

  1. 3 weeks ago
    Anonymous

    >I don't grok the idea of binding an object to a name, and so I don't grok anything that follows from it.

    • 3 weeks ago
      Anonymous

      It's still dumb

      • 3 weeks ago
        Anonymous

        you being a dumb moron making a thread complaining about something you don't understand doesn't make it dumb, it makes you dumb

        • 3 weeks ago
          Anonymous

          Ok make the "a" member const, smartypants

          • 3 weeks ago
            Anonymous
      • 3 weeks ago
        Anonymous

        there was motions to try and make "records" or whatever in javascript, but it's probably in committee hell still.
        the bigger problem is you can't really use objects as keys, even with Map, it's based on the underlying location in memory, not the actual value of.

        honestly all they need to do is add something like toString for == / ===

        >using plain javascript in 2024
        ngmi

        >default any prevents you from writing into a type that doesn't have .a property
        ok.

        • 3 weeks ago
          Anonymous

          https://github.com/tc39/proposal-record-tuple

          kek, still stage 2. I still kek having to serialize and deserialize objects just to have proper value compare. meme language.

        • 3 weeks ago
          Anonymous

          Why do sóydevs keep trying to make javascript a stricter language? there are trillions of languages out there that are strict, literally go use them

          • 3 weeks ago
            Anonymous

            js for frontend
            js for backend
            js everywhere

    • 3 weeks ago
      Anonymous

      >grok

    • 3 weeks ago
      Anonymous

      >grok
      back to hacker reddits please

  2. 3 weeks ago
    Anonymous

    Isn't const for variables, not for objects?
    If x was read only you could not define .a at all.

    • 3 weeks ago
      Anonymous

      You are not changing out the object the variable is pointing to. You can change the object itself, but x will always point to it and not another object.

    • 3 weeks ago
      Anonymous

      const x = {'a': 'moron'};

  3. 3 weeks ago
    Anonymous

    >writable: false
    Done t. Soiscript guru

  4. 3 weeks ago
    Anonymous

    it's a const pointer.
    it's not like jskiddies know anything about pointers.

    • 3 weeks ago
      Anonymous

      "const pointer" is ambiguous
      could be either
      Object const*
      or
      Object* const

      which mean different things (behavior in js is analogous to second case)

      • 3 weeks ago
        Anonymous

        No its not, the linguistic distinction is "constant pointer" and "pointer to a constant".

  5. 3 weeks ago
    Anonymous

    Are you actually looking for logic and sense in JS? just finish your client side code and be done with it. Questioning will only shorten your life

  6. 3 weeks ago
    Anonymous

    >using plain javascript in 2024
    ngmi

    • 3 weeks ago
      Anonymous

      >"compiling" a language with fake types into a language with no types
      ngmi

      • 3 weeks ago
        Anonymous

        Only a no-coder that has never touched a real typed language could cope like this. Writing anything more complex than fizzbuzz in plain Javascript is just a bug-ridden disaster.

        The actual solution to the Javascript problem is not using Javascript, though. But it is unavoidable in some situations unfortunately.

        • 3 weeks ago
          Anonymous

          I love Java and C# and types. But front end typescript is just unnecessary pain in ass especially when importing plain javascript libraries.

        • 3 weeks ago
          Anonymous

          JavaScript is the supreme programming language. Real typed languages are discriminatory. And TypeScript is just an abomination with no merits at all.

      • 3 weeks ago
        Anonymous

        ts+lua is very comfy

        • 3 weeks ago
          Anonymous

          transsexuals

      • 3 weeks ago
        Anonymous

        by that logic 99% of all types in large C/C++ codebases are not real types

    • 3 weeks ago
      Anonymous

      Those are just type errors, though.

    • 3 weeks ago
      Anonymous

      ts is pretty much just fake js.

  7. 3 weeks ago
    Anonymous

    Is there a good, short, introduction to javascript for people that know some other language (C, python) ?

    • 3 weeks ago
      Anonymous

      This is as good of an intro as you'll get

      https://github.com/getify/You-Dont-Know-JS/blob/1st-ed/README.md

      • 3 weeks ago
        Anonymous

        ty

  8. 3 weeks ago
    Anonymous

    >constant
    >not actually a constant
    I'm not JS dev or anything, but isn't there some other weird behaviours with strings or whatever?

    • 3 weeks ago
      Anonymous

      yes but const isnt weird here:

      commented version for idiots:
      int main() {
      const char * x = malloc(16);
      char * p = (char *) x; // tell the compiler we dont care
      strcpy(p, "lol");
      strcpy(p, "lmao");
      printf("%sn", p); // everything works
      }

      i still need someone to translate this to ebonics thoughever

      its completely normal, only zoomers with a superficial understanding of programming cant understand
      total cargo cultist death

    • 3 weeks ago
      Anonymous

      It is constant though.
      If you instead want an /immutable/ object, you use Object.freeze.

  9. 3 weeks ago
    Anonymous

    give one good reason why anything shouldn't be mutable

    • 3 weeks ago
      Anonymous

      Long story short because locking variables ensures API boundary safety

    • 3 weeks ago
      Anonymous

      compiler optimizations

  10. 3 weeks ago
    Anonymous

    >IQfy gets filtered by pointers again

    • 3 weeks ago
      Anonymous

      pointers are fricking moronic anyway
      thank god you can still earn 6 figures without ever bothering learning stupid pointers

      • 3 weeks ago
        Anonymous

        >i have some data
        >i point to it with a big red arrow
        >my big red arrow is constant and can't change
        >the data that my big red arrow points to can change
        is it really so complicated?

      • 3 weeks ago
        Anonymous

        >thank god you can still earn 6 figures without ever bothering learning stupid pointers
        holy shit the market hasn't corrected enough yet if this is still true

  11. 3 weeks ago
    Anonymous

    >no * anywhere
    >pointers
    wow it's as obscure as in shitty cnile libraries where they typedef a pointer

    • 3 weeks ago
      Anonymous

      all complex datatypes (arrays / objects) are basically pointers. Symbols are weird because their "value" is more of a description and sourcing global symbols is just weird imo.

  12. 3 weeks ago
    Anonymous

    I just made an explanation in Swift

    • 3 weeks ago
      Anonymous

      >but we can solve it with just two cope classes and three cope dependency injections and like ten constructors and also type eight times, bro, it's very easy!
      why is it that all languages have to use the most complicated constructs to force things to work?
      apparently const x = const {} is too damn intuitive and that's le bad

      • 3 weeks ago
        Anonymous

        Object.freeze already exists and has none of those problems.

        • 3 weeks ago
          Anonymous

          yeah consistent syntax would have been le bad, let's make const work only on lvalues
          great language design bro, just use Const.Constinator.ConstInit() bro

          • 3 weeks ago
            Anonymous

            It's certainly more consistent than having const sometimes mean const, and other times mean immutable, like what you're asking for.

          • 3 weeks ago
            Anonymous

            in which world are the two concepts not the same?

  13. 3 weeks ago
    Anonymous

    >x always points to the same object
    >you can still add and edit keys/values
    truly a mystery
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>

    int main() {
    const char * x = malloc(16);
    char * p = (char *) x;
    memset(p, 0, sizeof p);
    strcpy(p, "lol");
    strcpy(p, "lmao");
    printf("%sn", p);
    return 0;
    }

    • 3 weeks ago
      Anonymous

      commented version for idiots:
      int main() {
      const char * x = malloc(16);
      char * p = (char *) x; // tell the compiler we dont care
      strcpy(p, "lol");
      strcpy(p, "lmao");
      printf("%sn", p); // everything works
      }

      i still need someone to translate this to ebonics thoughever

  14. 3 weeks ago
    Anonymous

    It's impressive how 1st year kids make moronic threads like this as if they found something clever when in reality they just make a fool of themselves.

  15. 3 weeks ago
    Anonymous

    constant reference to an object with mutable members 🙂

    const ={};
    x.a="homie";
    y={};
    y.a="digga";
    x=y;

    console.log(x.a);

    ERROR!
    x=y;
    ^

    TypeError: Assignment to constant variable.

  16. 3 weeks ago
    Worm

    >Yawascript
    Trash lang

  17. 3 weeks ago
    Anonymous

    >const is actually a constant reference
    >object and arrays are reference based
    makes sense homosexual

  18. 3 weeks ago
    Anonymous

    >this board is plagues by morons like this
    what you're looking for is let x = Object.freeze({a: 'lol'});.

    • 3 weeks ago
      Anonymous

      >x = {}

    • 3 weeks ago
      Anonymous

      You would use const to prevent x from being reassigned, but otherwise yes this is the answer.

  19. 3 weeks ago
    Anonymous

    Websitters will jump to the defense of this because of sunk cost. Needfulscript has to die.

  20. 3 weeks ago
    Anonymous

    >not understanding references, primitive values and how const works in JS
    You have no idea how many people have been filtered to this where I work.

  21. 3 weeks ago
    Anonymous

    >variables are mutable by default
    Absolutely disgusting

    • 3 weeks ago
      Anonymous

      >variables are mutable

      It's in the name.

  22. 3 weeks ago
    Anonymous

    Const means the binding happens once at assignment, and cannot be changed. It doesn't mean everything is immutable.

  23. 3 weeks ago
    Anonymous

    The name is constant
    HAHAHAHAHAHAHAHAHA
    Js troons btfo !

    • 3 weeks ago
      Anonymous

      The only thing const in JS does is prevents something else to be assigned the same name.

  24. 3 weeks ago
    Anonymous

    Works on my machine

  25. 3 weeks ago
    Anonymous

    if you think this is somehow incoherent or nonsensical you're the biggest nocoder on IQfy and should be ashamed of shitting up the board like this
    const in JavaScript, and more broadly immutability in all programming languages, refers to the binding. in any language in existence you can do what's in the OP, what's not allowed is reassigning the variable itself, that's the whole point.

    • 3 weeks ago
      Anonymous

      >and more broadly immutability in all programming languages, refers to the binding.
      Nah, in C/C++ for example, const is part of the type itself.
      struct foo_t { int x; };

      const struct foo_t bar() {
      struct foo_t baz = { 1 };
      return baz;
      }

      int main() {
      printf("%in", bar().x);
      }
      Not that returning a const value is useful or anything. BUT, this property of const is why you can have things like const int*, where the binding is mutable but the value being pointed to isn't.

  26. 3 weeks ago
    Anonymous

    I'm not convinced most professional JS devs understand how const and let are supposed to be used

  27. 3 weeks ago
    Anonymous

    idk I don't understand meme languages

  28. 3 weeks ago
    Anonymous

    I lust use let for everything. isn't a const in JavaScript mutable?

Your email address will not be published. Required fields are marked *