Use let instead of var throughout. All modern browsers support it and have for many years, even the now-EOL IE11.[^ie]
Add a @ts-check annotation so that anyone working on a TS-enabled editor will get feedback inline about cases they may otherwise miss.
Add JSDoc-based type definitions for the script, and fix some errors that may occur at runtime. (These will be rare if they happen, but getting rid of them is still a win!)
screenshots to show it still works
![CleanShot 2024-05-22 at 15 48 22@2x](https://github.com/rust-lang/book/assets/2403023/e44505b0-8f6b-43f8-bf8a-e98466d64dee)
![CleanShot 2024-05-22 at 15 48 11@2x](https://github.com/rust-lang/book/assets/2403023/af0a376b-484d-47e5-84f1-0563772e3d5c)
[^ie]: IE11 did not correctly support the semantics of let for for loops, but the uses in the existing code here already used var in a way which would trigger the same behavior as using let does.
let
instead ofvar
throughout. All modern browsers support it and have for many years, even the now-EOL IE11.[^ie]@ts-check
annotation so that anyone working on a TS-enabled editor will get feedback inline about cases they may otherwise miss.screenshots to show it still works
![CleanShot 2024-05-22 at 15 48 22@2x](https://github.com/rust-lang/book/assets/2403023/e44505b0-8f6b-43f8-bf8a-e98466d64dee) ![CleanShot 2024-05-22 at 15 48 11@2x](https://github.com/rust-lang/book/assets/2403023/af0a376b-484d-47e5-84f1-0563772e3d5c)[^ie]: IE11 did not correctly support the semantics of
let
forfor
loops, but the uses in the existing code here already usedvar
in a way which would trigger the same behavior as usinglet
does.