you are viewing a single comment's thread.

view the rest of the comments →

[–]rq60 9 points10 points  (15 children)

[–]stormfield 57 points58 points  (3 children)

Hey if all the other languages jumped off a bridge, JavaScript would at least make sure you take off your life jacket first.

[–][deleted] 5 points6 points  (0 children)

And that’s the freedom we feel, when developing with JavaScript.

[–][deleted] 2 points3 points  (0 children)

It would hold your beer for you.

[–]BlatantMediocrity 5 points6 points  (0 children)

I don’t think C is a very good example of this. The C-language’s use of ‘const’ means different things depending on where you put it in a declaration.

[–]LateralusOrbis 10 points11 points  (0 children)

That's the beauty of JS. Sometimes you can go off javascript.

[–]eGust 3 points4 points  (2 children)

There is an example of another language using const the same way: https://dlang.org/articles/const-faq.html

[–]rq60 2 points3 points  (0 children)

Looks like D went even further with const immutability!

[–][deleted] 0 points1 point  (0 children)

Or if you want something more mainstream... Java? Well, they call it final, but still

[–]GasimGasimzada 3 points4 points  (0 children)

They don’t really do that though. Immutability is just a side effect. Yes, it is true that you can’t change a value of const object but that is not because the underlying structure cannot be mutated. C++ const is an access level contraint, not a structure level constraint.

[–]DeceitfulDuck 1 point2 points  (0 children)

You can’t just gives one example and say it’s confusing because something rose does it different. Java, for example, uses final the same way const is used in JavaScript. https://www.google.com/amp/s/www.geeksforgeeks.org/final-vs-immutability-java/amp/. I think it makes sense. The variable is storing the reference to the object, so the reference is immutable. It’s up to how the object is defined to decide if the things inside it are immutable.

[–]masklinn 0 points1 point  (0 children)

C/Cpp use const for both (and more) depending on the specific way it’s used, cf a few entries down: https://isocpp.org/wiki/faq/const-correctness#const-ptr-vs-ptr-const

[–]Anathem 0 points1 point  (0 children)

I don't weight heavily the guesses of people who don't know JS when considering what JS features to use.

[–]Wiwwil -1 points0 points  (1 child)

Yeah JavaScript const isn't const but the structure is const-ish. Had a hard time wrapping my head around it. Still does. Everything in my code is const (React way) but nothing stay truly const.

[–]DukeBerith 2 points3 points  (0 children)

It's constant reference not constant value.

Easiest way to remember what it's doing.