DEV Community

Discussion on: 🤔Pop Quiz! Which of these is an infinite loop?

Collapse
 
dpremus profile image
Danijel Premus

Fortunately my compiler will report an error If I try something like that.

I think that you should write some hint for beginners, that this kind variable naming is not good pratice and should be avoided.

Collapse
 
shiling profile image
Shi Ling

Oh yea I agree.

At the end, I reminded JD with this:

PSA: Use different names for counters in nested loops - to not only prevent errors, but helps in readability and clarity.

Not too sure if eslint helps with this, but I definitely wish there's an automatic way to catch it.

Collapse
 
dpremus profile image
Danijel Premus • Edited

I made same test with TypeScript and unfortunately this kind of code pass without warning. (:

After that I made same test with another language (Delphi) that Anders Hejlsberg (designer of TypeScript) designed 24 years ago and this old compiler report error. :)

I forgot to mention in my previous comment that your article is great.

Collapse
 
joshcheek profile image
Josh Cheek

This option looks promising: eslint.org/docs/rules/no-shadow

Thread Thread
 
shiling profile image
Shi Ling

Ahhhh yesss 👍