3 ms·
Heh, I like how you carefully worded that, because normally 'const' would signify that a variable is immutable in just about any other programming language in t
by russellbeattie 8y ago
Heh, I like how you carefully worded that, because normally 'const' would signify that a variable is immutable in just about any other programming language in the world. Except in JS, where const was awkwardly jammed into the language. I guarantee if the spec writers had known how badly const was going to be abused, they wouldn't have added it.
If you want a strongly typed language, go use C or Java and stop making JavaScript incomprehensible to all but the most pedantic developers.
- zbentley 8y ago> normally 'const' would signify that a variable is immutable in just about any other programming language in the world That's not true in Java, C, Ruby, or Perl (with the 'constant' prag-module), not really true in C++ (unless you're careful), and . . . generally just isn't true in most languages. While a few languages do add recursive immutability properties to their equivalent of 'const', most languages use the idea of a 'constant' only as a means of prohibiting name re-binding, not data modification. And even then, many languages that only prohibit const re-binding only do so in an optional (i.e. it's a warning) way. Many of those same languages do support immutable data structures either out of the box or via popular libraries (though in non-compiled language, such structures often come with a performance cost). They just don't call them const[ant]s. Edit: I'm also curious about how you think 'const' is being abused in JS. I'm not an expert in the language--this is a genuine question; not a veiled disagreement.
- anonytrary 8y agoAs long as you understand how `const` works in JS, I don't see it as in impediment. const x = {}; x.foo = "bar"; is not that confusing, because you aren't re-assigning x, you're mutating its data. Maybe `fixed` would have been a better name for it (like a vector that doesn't change direction but can change magnitude) if people think `const` should mean immutable.