update example code to use let/const instead of var #230
Labels
category: editorial
https://www.w3.org/policies/process/#class-2
Needs Edits
https://speced.github.io/spec-maintenance/about/
Milestone
There's a lot of example code in the spec that uses
var
, rather thanlet
/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 asfor (var x of inputs.values())
introduces a global variablex
, 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
andconst
, instead.The text was updated successfully, but these errors were encountered: