Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Explanation of 'const' does not convey mutability #50

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
arayi opened this issue Jan 6, 2017 · 6 comments
Closed

Explanation of 'const' does not convey mutability #50

arayi opened this issue Jan 6, 2017 · 6 comments

Comments

@arayi
Copy link

arayi commented Jan 6, 2017

In JS, const is NOT immutable—it can be changed but cannot be reassigned

(See https://mathiasbynens.be/notes/es6-const for a more detailed explanation)

I've seen this confuse many new devs, so I'd like to suggest including this information. I'll make a PR with the edit if you'd like. 🎉

@schoenwaldnils
Copy link
Contributor

Thats why I opened a PR #51
Maybe this issue is a duplicate to #31 ?

@arayi
Copy link
Author

arayi commented Jan 6, 2017

How is that addressed in PR #51 ?

See https://github.com/ryanmcdermott/clean-code-javascript#use-es6-constants-when-variable-values-do-not-change

This section seems to convey that const is for immutable values. "If the value changes, I change it to let" in #31 also seems to convey that const is for immutable values. So someone unfamiliar with how it is implemented may accidentally code something that modifies their const without reassigning it (which DOES work, unlike reassigning), and become very confused.

But no, this is not addressed in either of those.

@schoenwaldnils
Copy link
Contributor

schoenwaldnils commented Jan 6, 2017

Sorry, I misunderstood that the issue is about this paragraph.
True, my PR just fixes the use of let and const in the readme itself.

The paragraph has to be rewritten, of course.

@tonytran1
Copy link
Contributor

That's true, const properties can be changed and are mutable. The section was referring to primitive values of declared constants. Of course that's not their only use. Please update it to your understanding. Thanks.

@ryanmcdermott
Copy link
Owner

Thanks Arayi! You're right that the paragraph doesn't do the best job explaining the nature of the keyword const I think we should link to @mathiasbynens and @ericelliott for an authoritative educational stance on this. I would love a PR to accompany @schoenwaldnils awesome work!

This was referenced Jan 7, 2017
@ryanmcdermott
Copy link
Owner

This subsection was removed for the time being, until we come up with a better explanation for when to prefer const and how it helps improve refactorability.

ac47e82

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants