Timeline for How much should I be using 'let' vs 'const' in ES6?
Current License: CC BY-SA 3.0
17 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Aug 17, 2018 at 5:43 | comment | added | Pankaj Phartiyal | ES6 const is not actually a constant. It prohibits further assignment via = operator. The value is not immutable. Making objects and functions a const can lead to performance issue as they can't be garbage collected as their reference is immutable. | |
| Mar 29, 2017 at 8:06 | comment | added | wasatz | @TV'sFrank I agree, and this is also true with "readonly" in C#. However I believe that everything should be final/readonly by default even in these languages. Imho it is a design flaw in the languages that final isn't the default. I prefer languages such as F#/Rust where instead of having to mark things final you have to mark them as mutable. So in those languages everything is final by default, and the things that should be mutable has to be explicitly marked as mutable/mut etc. This is imho the good lang design choice, sadly this was not yet popular at the time that java/C# was designed. :( | |
| Mar 28, 2017 at 12:13 | comment | added | TV's Frank | One argument against something like "final" in Java is that it's extra noise - your brain has to process a bunch of extra information before getting to the parts that matter. This doesn't apply to javascript since "const" is a substitute for "let" rather than a prefix, so I won't object if someone suggests making const the norm instead of let. | |
| Jul 14, 2016 at 6:31 | comment | added | joeytwiddle | In older environments (e.g. Node v4) const can be false security: if you forgot to set strict mode then assignment will fail silently. Argh! (Fortunately this is fixed in ES6: Firefox, Chrome and Node v6 will throw an error on re-assignment, in or out of strict mode.) | |
| Jun 15, 2016 at 21:15 | comment | added | le_m | @Cerad const and immutable are two entirely different pairs of shoes. - I am sure you know, just pointing it out for those that don't. | |
| Apr 20, 2016 at 18:56 | comment | added | wasatz | @Pacerier I agree that it gets way too repetetive. But it helps in preventing bugs. You may want to have a look at languages that transpile to javascript instead, there are those where const is the default. ES6 is nice and all, but there are an increasing amount of better options popping up. Elm for example is amazing. | |
| Apr 20, 2016 at 16:06 | comment | added | Pacerier | The problem is that it gets way too repetitive to const const const const. It's the same problem with java statics: google.com/… | |
| Feb 5, 2016 at 9:02 | comment | added | Mathias Bynens | @Cerad Did you mean “4 characters less” or am I missing some joke here? | |
| May 22, 2015 at 9:23 | comment | added | backdesk | I agree with this answer but bear in mind that things aren't so obvious when working with things like plain objects or arrays as their properties can change even if they were defined with 'const'. I had thought of 'const' working like object.freeze but that's not the case. | |
| Apr 14, 2015 at 19:52 | comment | added | Kat | This seems a lot like using val in Scala (which declares a variable as immutable) and only using var (the mutable equivalent) when we can't use val. In other words, we declare variables as immutable by default and only introduce mutability when we absolutely need it (which may simply be because the mutable approach is cleaner). | |
| Apr 9, 2015 at 19:30 | comment | added | Keen | Seems like the go language gets this one right. Write const once, and apply it to multiple new symbols simultaneously. The number of characters saved scales linearly with the number of symbols you declare. | |
| Apr 9, 2015 at 18:57 | comment | added | Cerad | But 5 characters less than immutable. | |
| S Apr 9, 2015 at 17:20 | history | suggested | mskfisher | CC BY-SA 3.0 | const is two more chars than let |
| Apr 9, 2015 at 16:33 | review | Suggested edits | |||
| S Apr 9, 2015 at 17:20 | |||||
| Apr 9, 2015 at 14:49 | comment | added | OrangeDog | const is two more characters than let... | |
| Apr 9, 2015 at 14:12 | vote | accept | callum | ||
| Apr 9, 2015 at 13:26 | history | answered | wasatz | CC BY-SA 3.0 |