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

Let should be used instead of Var #450

Open
Invincible-Atlas opened this issue Feb 19, 2025 · 2 comments
Open

Let should be used instead of Var #450

Invincible-Atlas opened this issue Feb 19, 2025 · 2 comments

Comments

@Invincible-Atlas
Copy link

Basically what the title says. In all the examples, var is used to declare variables. However, it is better practice to use let.

@greggman
Copy link
Member

it is even better practice to use const instead of let where possible

unfortunately the articles were written before let and const were a thing and I don't have the time to re-write them.

While it might be possible to automate fixing the examples themselves, it's manual work to go fix all the corresponding articles across all languages.

Just replacing var with let won't work because many examples exploit the fact that you can redeclare a variable with var

var offset = 16;

...

var offset = 32;

but you can't do that with let

let offset = 16;

...

let offset = 32;  // error - offset is already declared

So it's not a simple as search and replace🙁

@Invincible-Atlas
Copy link
Author

I see how that could be a problem. Maybe a solution would be to have a disclaimer (for lack of a better word) at the start of the first article, stating that it is better to use let and const rather than var with an explanation of the differences between the three.

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

No branches or pull requests

2 participants