# Final variables

**URL:** <https://es.discourse.group/t/final-variables/299>\
**Category:** 💡 Ideas\
**Tags:** proposal\
**Created:** [April 9, 2020, 5:18am UTC](https://es.discourse.group/t/final-variables/299 "2020-04-09T05:18:42Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![badim65530](https://avatars.discourse-cdn.com/v4/letter/b/779978/32.png) [@badim65530](https://es.discourse.group/u/badim65530)\
**Post date:** [April 9, 2020, 5:18am UTC](https://es.discourse.group/t/final-variables/299/1 "2020-04-09T05:18:42Z")

</div>

Hi there!

The **const** keyword is kind of a bad design:

[https://jamie.build/const](https://jamie.build/const)

More and more great developers seem to acknowledge that:

> <https://twitter.com/dan_abramov/status/1208369896880558080>
>
> Dave Herman @littlecalculist

  

> <https://twitter.com/littlecalculist/status/917875241891676160>
>
> Yehuda Katz  🥨 @wycats

  

> <https://twitter.com/BrendanEich/status/1136774266035118080>
>
> BrendanEich @BrendanEich

**const** everywhere in modern JS is semantically weird and ugly (it's like hammering the wrong word again and again). It's not what you would expect in 99% of other programming languages out there. If brings confusion to new developers as well as experienced developers coming from other languages.

So I was wondering: how could we fix that? I mean, declaring variable is the basics of what is a programming language, yet JavaScript fails at that.

We could maybe introduce a true "no reassignment syntax" (final variables) that would look like that:

`let :foo = 'bar'; // can't reassign foo here in contrast to let foo = 'bar';`

It would also works elsewhere:

```javascript
for (let :value of iterable) {
}

```

```javascript
function (:param1, :param2) {
}

```

What do you think? I am not sure if this is a good idea or not, and I am not sure if there is a better character to use than the colon.

I think it's more elegant than using this wordy and semantically misleading `const`.

Thank you!

---

<div class="post-metadata">

**Author:** ![ljharb](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/ljharb/32/8_2.png) [@ljharb](https://es.discourse.group/u/ljharb)\
**Post date:** [April 9, 2020, 5:18pm UTC](https://es.discourse.group/t/final-variables/299/2 "2020-04-09T17:18:58Z")

</div>

That some people believe const was a mistake doesn't mean that's a universally held opinion, either outside or within TC39. I think `const` is wonderful, and not a mistake, and I think it should be used everywhere :-)

"Weird" and "ugly" are subjective preferences that are also not universally shared - on this topic or any other.

`const` means "constant reference", not "constant value", and I think that educating people of that is a much more viable option than introducing _another_ way to declare variables. `const` has shipped on the web (for 5+ years now) and can never be removed, so devs can't ever avoid needing to learn it anyways.

---

<div class="post-metadata">

**Author:** ![claudiameadows](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/claudiameadows/32/126_2.png) [@claudiameadows](https://es.discourse.group/u/claudiameadows)\
**Post date:** [April 9, 2020, 6:18pm UTC](https://es.discourse.group/t/final-variables/299/3 "2020-04-09T18:18:17Z")

</div>

And to add to that, the JVM world is the exception in calling their constant references `final` - most other languages use `const`. Even the K combinator in lambda calculus, `x => ignored => x`, is typically named `const` in most functional languages that implement it (like Haskell), and the result, `const x` (equivalent to `ignored => x`), is itself more conceptually a constant reference rather than a constant value.

---

<div class="post-metadata">

**Author:** ![badim65530](https://avatars.discourse-cdn.com/v4/letter/b/779978/32.png) [@badim65530](https://es.discourse.group/u/badim65530)\
**Post date:** [April 9, 2020, 6:24pm UTC](https://es.discourse.group/t/final-variables/299/4 "2020-04-09T18:24:55Z")

</div>

I appreciate your answer Jordan! Thank you! 😍

It's really hard to discuss stuff like that, because it's really about how we "feel" or "believe", not really about "real metrics". Is const really useful in a codebase or is it just wishful thinking? I have programmed in many languages in my career and I never had a single problem related to variable reassignment.

Yes in JavaScript const means "constant reference", not "constant value", but in computer science semantics, it's always a "constant value" like constant PI = 3.14. The keyword "final" would maybe better catch the idea of "constant reference".

```javascript
let final foo = 'bar';

function (final foo) {
}

```

So we can use const to semantically signify a "constant value"?

Anyway, I hope one day I could ditch let and const altogether and do something like that in JS:

```javascript
string foo = 'bar';

```

🕶

---

<div class="post-metadata">

**Author:** ![badim65530](https://avatars.discourse-cdn.com/v4/letter/b/779978/32.png) [@badim65530](https://es.discourse.group/u/badim65530)\
**Post date:** [April 9, 2020, 6:29pm UTC](https://es.discourse.group/t/final-variables/299/5 "2020-04-09T18:29:43Z")

</div>

Thanks Isiah! I didn't know that! 😊

---

<div class="post-metadata">

**Author:** ![badim65530](https://avatars.discourse-cdn.com/v4/letter/b/779978/32.png) [@badim65530](https://es.discourse.group/u/badim65530)\
**Post date:** [April 9, 2020, 7:30pm UTC](https://es.discourse.group/t/final-variables/299/6 "2020-04-09T19:30:22Z")

</div>

Here is an interesting Twitter thread about what's wrong with const:

> <https://twitter.com/littlecalculist/status/917899100103753728>

---

<div class="post-metadata">

**Author:** ![Jonas\_Wilms](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/jonas_wilms/32/189_2.png) [@Jonas\_Wilms](https://es.discourse.group/u/Jonas_Wilms)\
**Post date:** [April 14, 2020, 5:36pm UTC](https://es.discourse.group/t/final-variables/299/7 "2020-04-14T17:36:37Z")

</div>

So to summarize:

You complain about `const` because it's confusing to people from other languages, and then you propose `let :foo` ? Ask one of those folks on twitter what they think your syntax means. I guess no one will even get close to the actual meaning.

Also ... what is that new syntax supposed to do? A mere replacement for `const`? In that case you are a bit late to the party .... Or is it supposed to provide "real immutability"? If so, how? Freezing objects? Immutable References that do not support [[Set]] operations? What happens if you pass a `:frozen` to another function? Is it immutability there too?

Also mixed with object destructuring you can get full immutability also for objects with `const`, so I don't really get the point of those ranting:

`const { name, age } = retrieveUser();`
