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

update example code to use let/const instead of var #230

Closed
Pomax opened this issue Mar 8, 2022 · 3 comments · Fixed by #270
Closed

update example code to use let/const instead of var #230

Pomax opened this issue Mar 8, 2022 · 3 comments · Fixed by #270
Assignees
Labels
category: editorial https://www.w3.org/policies/process/#class-2 Needs Edits https://speced.github.io/spec-maintenance/about/
Milestone

Comments

@Pomax
Copy link

Pomax commented Mar 8, 2022

There's a lot of example code in the spec that uses var, rather than let/const, thus very much not doing what one might think. var does not follow "normal" block scoping rules, instead always being function or global scoped: a statement such as for (var x of inputs.values()) introduces a global variable x, not a variable that is scoped to the loop, and does so at the start of the script because the JS parser will hoist it over to the start of the function/global scope before actually running the code.

As a fairly modern API, it would be a good idea to update all the code used to illustrate its use to use the normal block-scoped let and const, instead.

@djipco
Copy link

djipco commented Mar 8, 2022

I totally understand your point and it would probably be a good idea to update the examples. However, there is nothing abnormal about using var. It is a perfectly valid way of specifying variables which comes, as you stated, with its own set of scoping rules which are well-documented and probably known by developers who can tell the difference between var, let and const.

Having said that, we probably want to promote contemporary coding practices. Can anyone see any reason why we should keep var (besides inertia) ?

@mjwilson-google mjwilson-google added the category: editorial https://www.w3.org/policies/process/#class-2 label Sep 13, 2023
@mjwilson-google mjwilson-google added this to the CR milestone Sep 14, 2023
@mjwilson-google mjwilson-google added the Needs Edits https://speced.github.io/spec-maintenance/about/ label Sep 30, 2023
@mjwilson-google
Copy link
Contributor

The examples have been moved to the explainer, and if there are no objections we can do this anytime.

@mjwilson-google mjwilson-google modified the milestones: CR, future-work Oct 3, 2023
@mjwilson-google
Copy link
Contributor

There are actually two examples still in the main body of the spec, each of which uses var three times:

So I will move the milestone back to CR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category: editorial https://www.w3.org/policies/process/#class-2 Needs Edits https://speced.github.io/spec-maintenance/about/
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants