Skip to content
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

When to use const or let #1645

Open
CyberMew opened this issue Dec 2, 2019 · 6 comments
Open

When to use const or let #1645

CyberMew opened this issue Dec 2, 2019 · 6 comments

Comments

@CyberMew
Copy link
Contributor

@CyberMew CyberMew commented Dec 2, 2019

https://javascript.info/variables

I think it would be good to indicate which is more preferred, i.e. instead of just saying what it does, adding the when to use will be better. For example const would be preferred/recommend whenever possible because you can't modify the value by accident or prevent some other programmer from reusing it for other stuffs and it helps with debugging in the long run. It is not mainly just for constants most of the time, the article worded it out to be that way. Maybe under best practices section or something?

@iliakan
Copy link
Member

@iliakan iliakan commented Dec 2, 2019

A good idea. Could you make a PR with such addition?

@icncsx
Copy link

@icncsx icncsx commented Mar 24, 2020

Hey @iliakan , can I work on this?

@iliakan
Copy link
Member

@iliakan iliakan commented Mar 24, 2020

Here's an excerpt:

When a programmer is sure that a variable will never change, they can declare it with const to guarantee and clearly communicate that fact to everyone.

Surely you can try to improve the article, @icncsx!

@moustachio-belvedere
Copy link

@moustachio-belvedere moustachio-belvedere commented Apr 28, 2020

Is it also worth mentioning compiler optimisations that may occur with different variable types? I like what you have there already @iliakan , just wondering if it might be appropriate to add speed considerations as well.

@iliakan
Copy link
Member

@iliakan iliakan commented Apr 28, 2020

An article about optimizations and internals of JS engines could be useful.

@icncsx
Copy link

@icncsx icncsx commented May 30, 2020

@iliakan Better late than never right? I made a PR - albeit for a separate reason re: redeclaration syntax error for let and const. I can raise an issue if you'd like. See: #1931

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

Successfully merging a pull request may close this issue.

None yet
4 participants
You can’t perform that action at this time.