DEV Community

Discussion on: Constants are not really constants

Collapse
 
sadick profile image
Sadick

What name do you think would be appropriate for const as they are in javascript since they are not really constants?

Collapse
 
aminnairi profile image
Amin

That's an interesting question. Thanks for asking!

In my opinion, I don't think that we should rename the keyword, but instead change the behavior of this keyword for objects and arrays especially.

That would make more sense to me. What do you think?

Collapse
 
sadick profile image
Sadick

I agree that changing the behaviour makes sense. But what if we wanted to maintain the behaviour, what name could we give to that behaviour. cannot reassign but can modify.

Thread Thread
 
aminnairi profile image
Amin

We could follow the path taken by Elm and their awesome error messages like:

I saw you used a constant here:

const fruits = [...];
      ^
      |
     here

It seems like you tried to update one of its member:

fruits[0] = ...
       ^
       |
      here

I think that you might wanna use Object.freeze to prevent causing side effects

const fruits = Object.freeze([...]);